File tree Expand file tree Collapse file tree 3 files changed +44
-5
lines changed Expand file tree Collapse file tree 3 files changed +44
-5
lines changed Original file line number Diff line number Diff line change @@ -43,9 +43,15 @@ FROM node:18.18-alpine
43
43
44
44
# runtime args and environment variables
45
45
ARG NODE_ENV=production
46
+ ARG RI_HOSTNAME
47
+ ARG RI_APP_PORT=5000
48
+ ARG RI_SERVER_TLS
46
49
ARG RI_SERVER_TLS_CERT
47
50
ARG RI_SERVER_TLS_KEY
48
51
ARG SEGMENT_WRITE_KEY
52
+ ENV RI_HOSTNAME=${RI_HOSTNAME}
53
+ ENV RI_APP_PORT=${RI_APP_PORT}
54
+ ENV RI_SERVER_TLS=${RI_SERVER_TLS}
49
55
ENV RI_SERVER_TLS_CERT=${RI_SERVER_TLS_CERT}
50
56
ENV RI_SERVER_TLS_KEY=${RI_SERVER_TLS_KEY}
51
57
ENV SEGMENT_WRITE_KEY=${SEGMENT_WRITE_KEY}
Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import { WindowsAuthAdapter } from 'src/modules/auth/window-auth/adapters/window
14
14
import { AppModule } from './app.module' ;
15
15
import SWAGGER_CONFIG from '../config/swagger' ;
16
16
import LOGGER_CONFIG from '../config/logger' ;
17
+ import { createHttpOptions } from './utils/createHttpOptions' ;
17
18
18
19
const serverConfig = get ( 'server' ) as Config [ 'server' ] ;
19
20
@@ -33,10 +34,7 @@ export default async function bootstrap(): Promise<IApp> {
33
34
} ;
34
35
35
36
if ( serverConfig . tls && serverConfig . tlsCert && serverConfig . tlsKey ) {
36
- options . httpsOptions = {
37
- key : JSON . parse ( `"${ serverConfig . tlsKey } "` ) ,
38
- cert : JSON . parse ( `"${ serverConfig . tlsCert } "` ) ,
39
- } ;
37
+ options . httpsOptions = await createHttpOptions ( serverConfig ) ;
40
38
}
41
39
42
40
const app = await NestFactory . create < NestExpressApplication > (
@@ -70,7 +68,9 @@ export default async function bootstrap(): Promise<IApp> {
70
68
71
69
await app . listen ( port , serverConfig . listenInterface ) ;
72
70
logger . log ( {
73
- message : `Server is running on http(s)://localhost:${ port } ` ,
71
+ message : `Server is running on http(s)://${
72
+ serverConfig . listenInterface ?? 'localhost'
73
+ } :${ port } `,
74
74
context : 'bootstrap' ,
75
75
} ) ;
76
76
Original file line number Diff line number Diff line change
1
+ import { readFile } from 'fs/promises' ;
2
+ import { Config } from '.' ;
3
+
4
+ export const createHttpOptions = async ( serverConfig : Config [ 'server' ] ) => {
5
+ const { tlsKey, tlsCert } = serverConfig ;
6
+
7
+ try {
8
+ const [ key , cert ] = await Promise . all ( [
9
+ readFile ( tlsKey , { encoding : 'utf-8' } ) ,
10
+ readFile ( tlsCert , { encoding : 'utf-8' } ) ,
11
+ ] ) ;
12
+ return {
13
+ key,
14
+ cert,
15
+ } ;
16
+ } catch ( e ) {
17
+ /* if this throws, it could mean
18
+ 1. the tlsKey and tlsCert provided by the config were actually certificates in PEM format, not file paths or
19
+ 2. there were issues reading the files (wrong path, permissions, etc.)
20
+
21
+ nothing to do in this case except assume PEM format and let the calling code throw if that doesn't work either */
22
+ }
23
+
24
+ // for docker and perhaps other environments, multi-line env vars are problematic, so if there are escaped new-lines
25
+ // in the key or cert, replace them with proper newlines
26
+ const key = tlsKey . replace ( / \\ n / g, '\n' ) ;
27
+ const cert = tlsCert . replace ( / \\ n / g, '\n' ) ;
28
+
29
+ return {
30
+ key,
31
+ cert,
32
+ } ;
33
+ } ;
You can’t perform that action at this time.
0 commit comments