From 9df8715f3ecab8974b512b86c3d945715aa7f19f Mon Sep 17 00:00:00 2001 From: sahalali Date: Fri, 19 Apr 2024 13:15:01 +0530 Subject: [PATCH] added https certificate --- .github/workflows/deploy-to-test-server.yml | 7 ++++++ src/config/system.config.ts | 5 +++++ src/main.ts | 24 +++++++++++++++++++-- 3 files changed, 34 insertions(+), 2 deletions(-) diff --git a/.github/workflows/deploy-to-test-server.yml b/.github/workflows/deploy-to-test-server.yml index 0b8917e..45bd517 100644 --- a/.github/workflows/deploy-to-test-server.yml +++ b/.github/workflows/deploy-to-test-server.yml @@ -46,6 +46,13 @@ jobs: uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + + - name: Create secret key files + run: | + mkdir -p secrets + echo "${{ secrets.AWS_PRIVATE_KEY }}" | base64 -d >> secrets/private-key.pem + echo "${{ secrets.PUBLIC_CERTIFICATE_PEM}}" | base64 -d >> secrets/public-certificate.pem + - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: diff --git a/src/config/system.config.ts b/src/config/system.config.ts index 80d2922..c733345 100644 --- a/src/config/system.config.ts +++ b/src/config/system.config.ts @@ -6,3 +6,8 @@ const { env } = process; export const ARTSDATA: { ENDPOINT: string } = { ENDPOINT: env.ARTSDATA_ENDPOINT || "https://db.artsdata.ca/" }; + +export const APPLICATION = { + HTTP_PORT: Number(env.APP_PORT) || 3000, + HTTPS_PORT: Number(env.APP_PORT) || 3000 +}; diff --git a/src/main.ts b/src/main.ts index 4ca0972..f1c8f41 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,9 +1,26 @@ import { NestFactory } from "@nestjs/core"; import { DocumentBuilder, SwaggerModule } from "@nestjs/swagger"; +import { ExpressAdapter } from "@nestjs/platform-express"; import { AppModule } from "./app.module"; +import { APPLICATION } from "./config/system.config"; +import * as express from "express"; +import * as fs from "fs"; +import * as http from "http"; +import * as https from "https"; + + async function bootstrap() { - const app = await NestFactory.create(AppModule); + const httpsOptions = { + key: fs.readFileSync("./secrets/private-key.pem"), + cert: fs.readFileSync("./secrets/public-certificate.pem") + }; + + const server = express(); + const app = await NestFactory.create( + AppModule, + new ExpressAdapter(server) + ); const config = new DocumentBuilder() .setTitle("Artsdata.ca Reconciliation Service") @@ -13,7 +30,10 @@ async function bootstrap() { const document = SwaggerModule.createDocument(app, config); SwaggerModule.setup("api", app, document); - await app.listen(3000); + await app.init(); + // http.createServer(server).listen(APPLICATION.HTTP_PORT); + https.createServer(httpsOptions, server).listen(APPLICATION.HTTPS_PORT); + } bootstrap();