1
0
mirror of https://github.com/sasjs/server.git synced 2026-01-09 07:20:05 +00:00

fix: release should also has https protocol

This commit is contained in:
Saad Jutt
2022-02-14 19:12:37 +05:00
parent 367b0f1f89
commit 0cfe724ffa
5 changed files with 40 additions and 30 deletions

View File

@@ -1,10 +1,40 @@
import path from 'path'
import { createServer } from 'https'
import { readFile } from '@sasjs/utils'
import appPromise from './app'
appPromise.then((app) => {
appPromise.then(async (app) => {
const protocol = process.env.PROTOCOL ?? 'http'
const sasJsPort = process.env.PORT ?? 5000
app.listen(sasJsPort, () => {
console.log(
`⚡️[server]: Server is running at http://localhost:${sasJsPort}`
)
})
if (protocol !== 'https') {
app.listen(sasJsPort, () => {
console.log(
`⚡️[server]: Server is running at http://localhost:${sasJsPort}`
)
})
} else {
const { key, cert } = await getCertificates()
const httpsServer = createServer({ key, cert }, app)
httpsServer.listen(sasJsPort, () => {
console.log(
`⚡️[server]: Server is running at https://localhost:${sasJsPort}`
)
})
}
})
const getCertificates = async () => {
const privkey = process.env.PRIVATE_KEY ?? 'privkey.pem'
const fullchain = process.env.FULL_CHAIN ?? 'fullchain.pem'
const keyPath = path.join(process.cwd(), privkey)
const certPath = path.join(process.cwd(), fullchain)
const key = await readFile(keyPath)
const cert = await readFile(certPath)
return { key, cert }
}