-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
26 lines (23 loc) · 735 Bytes
/
Copy pathserver.js
File metadata and controls
26 lines (23 loc) · 735 Bytes
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
import { createServer } from 'node:http';
import { readFileSync } from 'node:fs';
import { join, extname } from 'node:path';
const MIME = {
'.html': 'text/html',
'.js': 'application/javascript',
'.json': 'application/json',
'.wdr': 'text/plain',
'.css': 'text/css',
};
const PORT = 7788;
createServer((req, res) => {
const url = req.url === '/' ? '/index.html' : req.url;
const file = join('.', url.split('?')[0]);
try {
const body = readFileSync(file);
res.writeHead(200, { 'Content-Type': MIME[extname(file)] || 'text/plain' });
res.end(body);
} catch {
res.writeHead(404);
res.end('Not found');
}
}).listen(PORT, () => console.log(`OpenISD dev server → http://localhost:${PORT}`));