File tree Expand file tree Collapse file tree 4 files changed +54
-0
lines changed
Expand file tree Collapse file tree 4 files changed +54
-0
lines changed Original file line number Diff line number Diff line change 11# compiled output
22/dist
33/node_modules
4+ /certificates
45.env
56docker-compose.yml
67# Logs
Original file line number Diff line number Diff line change @@ -5,6 +5,13 @@ APP_NAME = "sesame-orchestrator"
55PLATFORM = "linux/amd64"
66include .env
77
8+ CERT_DIR = ./certificates
9+ COMMON_NAME = localhost
10+ DAYS_VALID = 365
11+
12+ $(shell mkdir -p $(CERT_DIR))
13+
14+
815.DEFAULT_GOAL := help
916help :
1017 @printf " \033[33mUsage:\033[0m\n make [target] [arg=\" val\" ...]\n\n\033[33mTargets:\033[0m\n"
@@ -126,3 +133,23 @@ ncu: ## Check latest versions of all project dependencies
126133
127134ncu-upgrade : # # Upgrade all project dependencies to the latest versions
128135 @npx npm-check-updates -u
136+
137+ generate-ssl-cert : # # Générer les certificats HTTPS auto-signés
138+ @echo " Génération des certificats HTTPS auto-signés..."
139+ @openssl req -x509 \
140+ -newkey rsa:4096 \
141+ -keyout $(CERT_DIR ) /server.key \
142+ -out $(CERT_DIR ) /server.crt \
143+ -days $(DAYS_VALID ) \
144+ -nodes \
145+ -subj " /CN=$( COMMON_NAME) "
146+ @chmod 600 $(CERT_DIR ) /server.key
147+ @chmod 644 $(CERT_DIR ) /server.crt
148+ @echo " Certificats générés avec succès dans $( CERT_DIR) "
149+
150+ clean-ssl-cert : # # Nettoyer les certificats HTTPS
151+ @rm -rf $(CERT_DIR )
152+ @echo " Certificats supprimés"
153+
154+ show-cert-info : # # Afficher les informations du certificat
155+ @openssl x509 -in $(CERT_DIR ) /server.crt -text -noout
Original file line number Diff line number Diff line change @@ -6,6 +6,7 @@ import { IAuthModuleOptions } from '@nestjs/passport';
66import { JwtModuleOptions } from '@nestjs/jwt' ;
77import { StorageManagerConfig } from '@the-software-compagny/nestjs_module_factorydrive' ;
88import { AmazonWebServicesS3StorageConfig } from '@the-software-compagny/nestjs_module_factorydrive-s3' ;
9+ import { parse } from 'path' ;
910
1011export interface MongoosePlugin {
1112 package : string ;
@@ -19,6 +20,11 @@ export interface ConfigInstance {
1920 bodyParser : {
2021 limit : string ;
2122 } ;
23+ https : {
24+ enabled : boolean ;
25+ key : string ;
26+ cert : string ;
27+ }
2228 } ;
2329 helmet : HelmetOptions ;
2430 mongoose : {
@@ -79,6 +85,11 @@ export default (): ConfigInstance => ({
7985 bodyParser : {
8086 limit : '500mb' ,
8187 } ,
88+ https : {
89+ enabled : ! ! parseInt ( process . env [ 'SESAME_HTTPS_ENABLED' ] ) || false ,
90+ key : process . env [ 'SESAME_HTTPS_PATH_KEY' ] || '' ,
91+ cert : process . env [ 'SESAME_HTTPS_PATH_CERT' ] || '' ,
92+ } ,
8293 } ,
8394 helmet : {
8495 contentSecurityPolicy : {
Original file line number Diff line number Diff line change @@ -8,6 +8,7 @@ import { getLogLevel } from './_common/functions/get-log-level';
88import { AppModule } from './app.module' ;
99import configInstance from './config' ;
1010import { InternalLogger } from './core/logger/internal.logger' ;
11+ import { readFileSync } from 'fs' ;
1112
1213declare const module : any ;
1314( async ( ) : Promise < void > => {
@@ -17,11 +18,25 @@ declare const module: any;
1718 mongoose : cfg ?. mongoose ,
1819 } ) ;
1920 await logger . initialize ( ) ;
21+
22+ let httpsOptions = { } ;
23+ if ( cfg . application ?. https ?. enabled ) {
24+ try {
25+ httpsOptions = {
26+ key : readFileSync ( cfg . application ?. https ?. key ) ,
27+ cert : readFileSync ( cfg . application ?. https ?. cert ) ,
28+ } ;
29+ } catch ( error ) {
30+ logger . error ( 'Error while reading https key and cert' , error ) ;
31+ }
32+ }
33+
2034 const app = await NestFactory . create < NestExpressApplication > ( AppModule , {
2135 bodyParser : false ,
2236 rawBody : true ,
2337 cors : true ,
2438 logger,
39+ httpsOptions,
2540 } ) ;
2641 app . use ( ( _ : any , res : Response , next : ( ) => void ) => {
2742 res . removeHeader ( 'x-powered-by' ) ;
You can’t perform that action at this time.
0 commit comments