feat(nitro): ssl nitro support in production (#2742)

This commit is contained in:
Daniel Roe 2022-01-17 10:37:55 +00:00 committed by GitHub
parent 4b351504e8
commit 176716bdaf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,9 +1,13 @@
import '#polyfill'
import { Server } from 'http'
import { Server as HttpServer } from 'http'
import { Server as HttpsServer } from 'https'
import destr from 'destr'
import { handle } from '../server'
const server = new Server(handle)
const cert = process.env.NITRO_SSL_CERT
const key = process.env.NITRO_SSL_KEY
const server = cert && key ? new HttpsServer({ key, cert }, handle) : new HttpServer(handle)
const port = (destr(process.env.NUXT_PORT || process.env.PORT) || 3000) as number
const hostname = process.env.NUXT_HOST || process.env.HOST || 'localhost'
@ -14,7 +18,8 @@ server.listen(port, hostname, (err) => {
console.error(err)
process.exit(1)
}
console.log(`Listening on http://${hostname}:${port}`)
const protocol = cert && key ? 'https' : 'http'
console.log(`Listening on ${protocol}://${hostname}:${port}`)
})
export default {}