0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2024-12-30 20:33:54 -05:00

feat: add https support

This commit is contained in:
Gao Sun 2021-07-31 02:12:47 +08:00
parent 181f198260
commit 745cd22c16
No known key found for this signature in database
GPG key ID: 0F0EFA2E36639F31
2 changed files with 16 additions and 0 deletions

1
.gitignore vendored
View file

@ -24,3 +24,4 @@ cache
.*cache .*cache
.DS_Store .DS_Store
*.env *.env
*.pem

View file

@ -1,3 +1,5 @@
import https from 'https';
import fs from 'fs/promises';
import Koa from 'koa'; import Koa from 'koa';
import koaLogger from 'koa-logger'; import koaLogger from 'koa-logger';
@ -16,6 +18,19 @@ export default async function initApp(app: Koa): Promise<void> {
app.use(koaUIProxy()); 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, () => { app.listen(port, () => {
console.log(`App is listening on port ${port}`); console.log(`App is listening on port ${port}`);
}); });