-
Notifications
You must be signed in to change notification settings - Fork 13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add HTTPS option #19
base: master
Are you sure you want to change the base?
Add HTTPS option #19
Changes from all commits
ce3cbab
d586c7c
1786299
937dc13
700cc62
4aaea88
8b119f4
75341e8
7ffcaec
6c8c714
63cf0d2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -148,4 +148,14 @@ export class DuckyApiConfig { | |||||
@IsNumber() | ||||||
@Min(0) | ||||||
DELAY: number | ||||||
|
||||||
@IsOptional() | ||||||
@IsNotEmpty() | ||||||
@IsString() | ||||||
TLS_KEY_PATH: string | ||||||
|
||||||
@IsOptional() | ||||||
@IsNotEmpty() | ||||||
@IsString() | ||||||
TLS_CERT_PATH: string | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,8 @@ import fs from 'fs' | |
import Helmet from 'helmet' | ||
import { resolve } from 'path' | ||
import { promisify } from 'util' | ||
import { ExpressAdapter } from '@nestjs/platform-express' | ||
import * as express from 'express'; | ||
|
||
import { AppModule } from './app.module' | ||
import { UnauthorizedExceptionFilter } from './common/filters/unauthorized-exception.filter' | ||
|
@@ -15,7 +17,12 @@ const writeFile = promisify(fs.writeFile) | |
declare const module: any | ||
|
||
async function bootstrap(): Promise<void> { | ||
const app = await NestFactory.create(AppModule) | ||
const server = express.default() | ||
const app = await NestFactory.create( | ||
AppModule, | ||
new ExpressAdapter(server) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The only reason to do it this way I can see from the documention if for starting multiple servers at the same time (for example an http server next to an https server), which is not something that's happening right now. Is there a reason you did it this way as opposed to the standard nestjs config? |
||
) | ||
|
||
const config: ConfigService = app.get('ConfigService') | ||
|
||
if (config.SERVE_DUCKYPANEL) { | ||
|
@@ -55,8 +62,21 @@ async function bootstrap(): Promise<void> { | |
displayOperationId: true, | ||
}, | ||
}) | ||
|
||
await app.init() | ||
|
||
await app.listen(config.PORT) | ||
if (config.TLS_KEY_PATH && config.TLS_CERT_PATH) { | ||
const https = require('https') | ||
const fs = require('fs') | ||
Comment on lines
+69
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please make these import statements at the top of the file instead of requires. |
||
await https.createServer({ | ||
key: fs.readFileSync(config.TLS_KEY_PATH), | ||
cert: fs.readFileSync(config.TLS_CERT_PATH) | ||
}, server).listen(config.PORT) | ||
} | ||
else { | ||
const http = require('http') | ||
await http.createServer(server).listen(config.PORT) | ||
} | ||
|
||
if (module.hot) { | ||
module.hot.accept() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.