-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver-https.js
More file actions
27 lines (22 loc) · 757 Bytes
/
Copy pathserver-https.js
File metadata and controls
27 lines (22 loc) · 757 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
const fs = require('fs')
const https = require('https')
const next = require('next')
const port = parseInt(process.env.PORT || '3000', 10)
const dev = process.env.NODE_ENV !== 'production'
const app = next({ dev })
const handle = app.getRequestHandler()
const certPath = process.env.NEXT_SSL_CERT || './.certs/server.crt'
const keyPath = process.env.NEXT_SSL_KEY || './.certs/server.key'
app.prepare().then(() => {
const httpsOptions = {
key: fs.readFileSync(keyPath),
cert: fs.readFileSync(certPath),
}
const server = https.createServer(httpsOptions, (req, res) => {
return handle(req, res)
})
server.listen(port, (err) => {
if (err) throw err
console.log(`> HTTPS server listening at https://localhost:${port}`)
})
})