-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
30 lines (27 loc) · 907 Bytes
/
server.js
File metadata and controls
30 lines (27 loc) · 907 Bytes
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
import { createServer } from 'https';
import { parse } from 'url';
import next from 'next';
import { readFileSync } from 'fs';
import { resolve } from 'path';
const dev = process.env.NODE_ENV !== 'production';
const app = next({ dev });
const handle = app.getRequestHandler();
let httpsOptions;
try {
httpsOptions = {
key: readFileSync(resolve('/etc/letsencrypt/live/www.udongrang.com/privkey.pem')),
cert: readFileSync(resolve('/etc/letsencrypt/live/www.udongrang.com/fullchain.pem'))
};
} catch (err) {
console.error('Error reading SSL certificate files:', err);
process.exit(1);
}
app.prepare().then(() => {
createServer(httpsOptions, (req, res) => {
const parsedUrl = parse(req.url, true);
handle(req, res, parsedUrl);
}).listen(3000, (err) => {
if (err) throw err;
console.log('> Ready on https://localhost:3000');
});
});