-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlocal-server.js
More file actions
40 lines (34 loc) · 1.08 KB
/
local-server.js
File metadata and controls
40 lines (34 loc) · 1.08 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
const http = require('http');
const https = require('https');
const fs = require('fs');
const { parse } = require('url');
const next = require('next');
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
app.prepare().then(() => {
const HTTP_PORT = process.env.HTTP_PORT;
const HTTPS_PORT = process.env.HTTPS_PORT;
const httpServer = http.createServer((req, res) => {
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
});
const httpsServer = https.createServer(
{
cert: fs.readFileSync(`${process.env.HTTPS_CERT_PATH}.pem`),
key: fs.readFileSync(`${process.env.HTTPS_KEY_PATH}.pem`),
},
(req, res) => {
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
},
);
httpServer.listen(HTTP_PORT, (err) => {
if (err) throw err;
console.log(`> Ready on http://localhost:${HTTP_PORT}`);
});
httpsServer.listen(HTTPS_PORT, (err) => {
if (err) throw err;
console.log(`> Ready on https://localhost:${HTTPS_PORT}`);
});
});