-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserve.js
More file actions
49 lines (42 loc) · 1.66 KB
/
serve.js
File metadata and controls
49 lines (42 loc) · 1.66 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
import http from 'http';
import fs from 'fs';
import path from 'path';
import url from 'url';
const PORT = 3457;
const server = http.createServer((req, res) => {
// Parse URL to separate pathname from query string
const parsedUrl = url.parse(req.url, true);
const pathname = parsedUrl.pathname;
let filePath = './dist' + (pathname === '/' ? '/src/popup/index.html' : pathname);
// Handle root paths for different pages (strip query params for path matching)
if (pathname === '/popup') filePath = './dist/src/popup/index.html';
if (pathname === '/settings') filePath = './dist/src/settings/index.html';
if (pathname === '/sidepanel') filePath = './dist/src/sidepanel/index.html';
const ext = path.extname(filePath);
const mimeTypes = {
'.html': 'text/html',
'.js': 'application/javascript',
'.css': 'text/css',
'.png': 'image/png',
'.svg': 'image/svg+xml'
};
fs.readFile(filePath, (err, data) => {
if (err) {
res.writeHead(404);
res.end('Not found: ' + filePath);
return;
}
res.writeHead(200, { 'Content-Type': mimeTypes[ext] || 'text/plain' });
res.end(data);
});
});
server.listen(PORT, () => {
console.log('Server running on http://localhost:' + PORT);
console.log('Popup: http://localhost:' + PORT + '/popup');
console.log('Settings: http://localhost:' + PORT + '/settings');
console.log('Side Panel: http://localhost:' + PORT + '/sidepanel');
console.log('');
console.log('Testing URLs:');
console.log(' Unlocked state: http://localhost:' + PORT + '/popup?unlocked=true');
console.log(' With matching entry: http://localhost:' + PORT + '/popup?unlocked=true&testUrl=https://example.com');
});