-
Notifications
You must be signed in to change notification settings - Fork 11
/
server.js
32 lines (28 loc) · 1.09 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
const { createServer } = require('https');
const fs = require('fs');
const { parse } = require('url');
const next = require('next');
const dev = process.env.NODE_ENV !== 'production';
const port = process.env.PORT || 8766;
const app = next({ dev });
const handle = app.getRequestHandler();
(() => {
if (!fs.existsSync('./cert/localhost-key.pem') && !fs.existsSync('./cert/localhost.pem'))
return console.log(
'> 💔 Error: Please create the certificate file before running npm run dev -> https://github.com/paziresh24/patient/blob/main/CONTRIBUTING.md#your-connection-is-not-private',
);
const httpsOptions = {
key: fs.readFileSync('./cert/localhost-key.pem'),
cert: fs.readFileSync('./cert/localhost.pem'),
};
app.prepare().then(() => {
createServer(httpsOptions, (req, res) => {
const parsedUrl = parse(req.url, true);
const { pathname } = parsedUrl;
handle(req, res, parsedUrl);
}).listen(port, err => {
if (err) throw err;
console.log(`> Ready on https://localhost:${port} | https://local.paziresh24.com:${port} 🎉`);
});
});
})();