-
Notifications
You must be signed in to change notification settings - Fork 67
/
Copy pathstartup.js
36 lines (28 loc) · 826 Bytes
/
startup.js
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
const next = require('next');
const http = require('http');
const { createBareServer } = require('@tomphttp/bare-server-node');
const app = next({ dev: process.env.NODE_ENV !== 'production' });
const handle = app.getRequestHandler();
app.prepare();
const httpServer = http.createServer();
const bareServer = createBareServer('/bare/');
httpServer.on('request', (req, res) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeRequest(req, res);
} else {
handle(req,res);
}
});
httpServer.on('upgrade', (req, socket, head) => {
if (bareServer.shouldRoute(req)) {
bareServer.routeUpgrade(req, socket, head);
} else {
socket.end();
}
});
httpServer.on('listening', () => {
console.log(' > PIKL ready on port 3000');
});
httpServer.listen({
port: 3000,
});