-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathserver.js
36 lines (33 loc) · 1.01 KB
/
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
// const { createServer } = require("https");
// const { parse } = require("url");
// const next = require("next");
// const fs = require("fs");
import {createServer} from 'https';
import {parse} from 'url';
import next from 'next';
import fs from 'fs';
const SERVER_ADDR = '0.0.0.0';
const SERVER_NAME = 'local.webaverse.com';
const port = parseInt(process.env.PORT, 10) || 4444;
const dev = process.env.NODE_ENV !== 'production';
const app = next({
dev,
});
const handle = app.getRequestHandler();
const httpsOptions = {
cert: fs.readFileSync('./certs-local/fullchain.pem'),
key: fs.readFileSync('./certs-local/privkey.pem'),
};
app.prepare()
.then(() => {
createServer(httpsOptions, (req, res) => {
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
}).listen(port, SERVER_ADDR, (err) => {
if (err) throw err;
console.log(`https://${SERVER_NAME}:${port}/`);
console.log('ready');
});
}).catch(err => {
throw err;
});