-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
211 lines (196 loc) · 5.93 KB
/
server.js
File metadata and controls
211 lines (196 loc) · 5.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
const http = require('http');
const fs = require('fs');
const path = require('path');
const PORT = 5000;
const mimeTypes = {
'.html': 'text/html',
'.js': 'text/javascript',
'.css': 'text/css',
'.json': 'application/json',
'.png': 'image/png',
'.jpg': 'image/jpg',
'.gif': 'image/gif',
'.svg': 'image/svg+xml',
'.ico': 'image/x-icon',
'.md': 'text/markdown',
};
const server = http.createServer((req, res) => {
console.log(`${req.method} ${req.url}`);
let filePath = '.' + req.url;
if (filePath === './') {
filePath = './sidebar.html';
}
const extname = String(path.extname(filePath)).toLowerCase();
const mimeType = mimeTypes[extname] || 'application/octet-stream';
fs.readFile(filePath, (error, content) => {
if (error) {
if (error.code === 'ENOENT') {
res.writeHead(404, { 'Content-Type': 'text/html' });
res.end(`
<!DOCTYPE html>
<html>
<head>
<title>Meme Studio Extension - Documentation</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background: #f5f5f5;
color: #333;
}
.header {
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
color: white;
padding: 40px;
border-radius: 10px;
margin-bottom: 30px;
}
.card {
background: white;
padding: 30px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
margin-bottom: 20px;
}
h1 { margin: 0 0 10px 0; }
h2 { color: #667eea; margin-top: 0; }
ul { line-height: 1.8; }
a { color: #667eea; text-decoration: none; }
a:hover { text-decoration: underline; }
.footer {
text-align: center;
padding: 20px;
color: #666;
}
code {
background: #f0f0f0;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
}
</style>
</head>
<body>
<div class="header">
<h1>🎨 Meme Studio - Chrome Extension</h1>
<p>Welcome to the development server! This server helps you view documentation and extension files.</p>
</div>
<div class="card">
<h2>📚 Documentation</h2>
<ul>
<li><a href="/README.md">README.md</a> - Main documentation</li>
<li><a href="/CONTRIBUTING.md">CONTRIBUTING.md</a> - How to contribute</li>
<li><a href="/CODE_OF_CONDUCT.md">CODE_OF_CONDUCT.md</a> - Community guidelines</li>
<li><a href="/LICENSE">LICENSE</a> - MIT License</li>
<li><a href="/CHANGELOG.md">CHANGELOG.md</a> - Version history</li>
</ul>
</div>
<div class="card">
<h2>🔧 Extension Files</h2>
<ul>
<li><a href="/manifest.json">manifest.json</a> - Extension configuration</li>
<li><a href="/sidebar.html">sidebar.html</a> - Main UI</li>
<li><a href="/sidebar.js">sidebar.js</a> - Core JavaScript</li>
<li><a href="/background.js">background.js</a> - Service worker</li>
</ul>
</div>
<div class="card">
<h2>🚀 How to Load in Chrome</h2>
<ol>
<li>Open Chrome and go to <code>chrome://extensions/</code></li>
<li>Enable "Developer mode" (toggle in top-right)</li>
<li>Click "Load unpacked"</li>
<li>Select this project directory</li>
<li>Click the extension icon to use it!</li>
</ol>
</div>
<div class="footer">
<p>Made with ❤️ by the Meme Studio community</p>
<p>This is a development server running on port ${PORT}</p>
</div>
</body>
</html>
`, 'utf-8');
} else {
res.writeHead(500);
res.end(`Server Error: ${error.code}`);
}
} else {
if (extname === '.md') {
res.writeHead(200, { 'Content-Type': 'text/html' });
res.end(`
<!DOCTYPE html>
<html>
<head>
<title>Meme Studio - ${path.basename(filePath)}</title>
<style>
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
max-width: 900px;
margin: 0 auto;
padding: 20px;
background: #f5f5f5;
color: #333;
line-height: 1.6;
}
.container {
background: white;
padding: 40px;
border-radius: 10px;
box-shadow: 0 2px 10px rgba(0,0,0,0.1);
}
pre {
background: #f0f0f0;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
}
code {
background: #f0f0f0;
padding: 2px 6px;
border-radius: 3px;
font-family: 'Courier New', monospace;
}
a { color: #667eea; }
h1, h2, h3 { color: #667eea; }
.back { margin-bottom: 20px; }
</style>
</head>
<body>
<div class="container">
<div class="back"><a href="/">← Back to home</a></div>
<pre>${content.toString().replace(/</g, '<').replace(/>/g, '>')}</pre>
</div>
</body>
</html>
`, 'utf-8');
} else {
res.writeHead(200, { 'Content-Type': mimeType });
res.end(content, 'utf-8');
}
}
});
});
server.listen(PORT, '0.0.0.0', () => {
console.log(`
╔═══════════════════════════════════════════════════════╗
║ 🎨 Meme Studio Extension - Development Server ║
╚═══════════════════════════════════════════════════════╝
✓ Server running at: http://0.0.0.0:${PORT}
✓ Documentation available at: http://localhost:${PORT}
📚 Available endpoints:
• / - Home page
• /README.md - Main documentation
• /CONTRIBUTING.md - Contribution guidelines
• /manifest.json - Extension manifest
• /sidebar.html - Main UI file
🔧 To load the extension in Chrome:
1. Open chrome://extensions/
2. Enable "Developer mode"
3. Click "Load unpacked"
4. Select this directory
Press Ctrl+C to stop the server
`);
});