diff --git a/.gitignore b/.gitignore index 6fba8d211..50acac010 100644 --- a/.gitignore +++ b/.gitignore @@ -24,3 +24,4 @@ cache .*cache .DS_Store *.env +*.pem diff --git a/packages/core/src/init/app.ts b/packages/core/src/init/app.ts index 34b0efbb6..7b7052aec 100644 --- a/packages/core/src/init/app.ts +++ b/packages/core/src/init/app.ts @@ -1,3 +1,5 @@ +import https from 'https'; +import fs from 'fs/promises'; import Koa from 'koa'; import koaLogger from 'koa-logger'; @@ -16,6 +18,19 @@ export default async function initApp(app: Koa): Promise { app.use(koaUIProxy()); + const { HTTPS_CERT, HTTPS_KEY } = process.env; + if (HTTPS_CERT && HTTPS_KEY) { + https + .createServer( + { cert: await fs.readFile(HTTPS_CERT), key: await fs.readFile(HTTPS_KEY) }, + app.callback() + ) + .listen(port, () => { + console.log(`App is listening on port ${port} with HTTPS`); + }); + return; + } + app.listen(port, () => { console.log(`App is listening on port ${port}`); });