-
Notifications
You must be signed in to change notification settings - Fork 2
/
dev-server.js
42 lines (38 loc) · 1.09 KB
/
dev-server.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
37
38
39
40
41
42
const { createServer } = require("https");
const { parse } = require("url");
const next = require("next");
const fs = require("fs");
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
const port = 3000;
const httpsOptions = {
key: fs.readFileSync("./localhost.key"),
cert: fs.readFileSync("./localhost.crt")
};
/**
* To determine the user's IP address, we query the node.js networkInterfaces object and
* ignore any non-IPv4 and internal (e.g. 127.0.0.1) addresses
*/
var ipAddr = Object.values(require("os").networkInterfaces()).reduce(
(r, list) =>
r.concat(
list.reduce(
(rr, i) =>
rr.concat((i.family === "IPv4" && !i.internal && i.address) || []),
[]
)
),
[]
);
app.prepare().then(() => {
createServer(httpsOptions, (req, res) => {
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
}).listen(port, "0.0.0.0", err => {
if (err) throw err;
console.log(
`> Ready on https://localhost:${port} and https://${ipAddr}:${port}`
);
});
});