-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbare.mjs
More file actions
31 lines (25 loc) · 644 Bytes
/
bare.mjs
File metadata and controls
31 lines (25 loc) · 644 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
27
28
29
30
31
import http from 'node:http';
import { createBareServer } from '@tomphttp/bare-server-node';
const httpServer = http.createServer();
const bareServer = createBareServer('/bare/');
httpServer.on('request', (req, res) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeRequest(req, res);
} else {
res.writeHead(400);
res.end('Not found.');
}
});
httpServer.on('upgrade', (req, socket, head) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeUpgrade(req, socket, head);
} else {
socket.end();
}
});
httpServer.on('listening', () => {
console.log('HTTP server listening');
});
httpServer.listen({
port: 3300,
});