From 61c05d250880a6737dd4e15b323c632f268a289b 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 | 3 ++- src/config/system.config.ts | 5 +++++ src/main.ts | 24 +++++++++++++++++++-- 3 files changed, 29 insertions(+), 3 deletions(-) diff --git a/.github/workflows/deploy-to-test-server.yml b/.github/workflows/deploy-to-test-server.yml index 0b8917e..5b3ce2c 100644 --- a/.github/workflows/deploy-to-test-server.yml +++ b/.github/workflows/deploy-to-test-server.yml @@ -46,6 +46,7 @@ jobs: uses: docker/metadata-action@98669ae865ea3cffbcbaa878cf57c20bbf1c6c38 with: images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }} + - name: Build and push Docker image uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc with: @@ -66,5 +67,5 @@ jobs: run: | echo "$PRIVATE_KEY" > private_key && chmod 600 private_key - ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} ' docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.PAT }} && docker pull ghcr.io/${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main && docker images && docker ps -q --filter name=artsdata-reconciliation | xargs -r docker rm -f && docker run -itd --restart always -p 3000:3000 --name artsdata-reconciliation ghcr.io/${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main && docker image prune -a -f' + ssh -o StrictHostKeyChecking=no -i private_key ${USER_NAME}@${HOSTNAME} ' docker login ghcr.io -u ${{ github.actor }} -p ${{ secrets.PAT }} && docker pull ghcr.io/${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main && docker images && docker ps -q --filter name=artsdata-reconciliation | xargs -r docker rm -f && docker run -itd --restart always -p 3000:3000 --name artsdata-reconciliation ghcr.io/${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:main && docker image prune -a -f && docker cp ./secrets artsdata-reconciliation:./usr/src/app/secrets' 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();