-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathserver.js
33 lines (29 loc) · 1003 Bytes
/
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
const { createServer } = require("https");
const { parse } = require("url");
const next = require("next");
const fs = require("fs");
const os = require("os");
const path = require("path");
const dev = process.env.NODE_ENV !== "production";
const app = next({ dev });
const handle = app.getRequestHandler();
const homedir = os.homedir();
const caPath =
process.env.ROOT_CA_PATH ||
path.resolve(homedir, "Library/Application Support/mkcert/rootCA.pem");
const certPath = path.resolve(__dirname, "./localhost.pem");
const keyPath = path.resolve(__dirname, "./localhost-key.pem");
const httpsOptions = {
ca: fs.readFileSync(caPath),
cert: fs.readFileSync(certPath),
key: fs.readFileSync(keyPath),
};
app.prepare().then(() => {
createServer(httpsOptions, (req, res) => {
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
}).listen(process.env.PORT, (err) => {
if (err) throw err;
console.log(`> Ready on https://localhost:${process.env.PORT}`);
});
});