-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.mjs
35 lines (28 loc) · 899 Bytes
/
app.mjs
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
import createBareServer from '@tomphttp/bare-server-node';
import http from 'http';
import nodeStatic from 'node-static';
import * as custombare from './static/customBare.mjs';
const PORT = process.env.PORT || 1131;
const bareServer = createBareServer('/bare/', {
logErrors: false,
localAddress: undefined
});
const serve = new nodeStatic.Server('static/');
const server = http.createServer();
server.on('request', (request, response) => {
if (custombare.route(request, response)) return true;
if (bareServer.shouldRoute(request)) {
bareServer.routeRequest(request, response);
} else {
serve.serve(request, response);
}
});
server.on('upgrade', (req, socket, head) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeUpgrade(req, socket, head);
} else {
socket.end();
}
});
server.listen(PORT);
console.log(`Server running at http://localhost:${PORT}/.`);