From d0d7a5da919bf33c2dc913913308d2713a568e6f Mon Sep 17 00:00:00 2001 From: Ahmed Saeed Date: Sat, 23 Mar 2024 00:26:00 +0200 Subject: [PATCH] Fix public key path to read file contents dynamically by generated JS files after build - Substitute the `mkdir` step from deployment actions by keeping track of the certs dir. --- .github/workflows/render-build-deploy.yml | 1 - .gitignore | 5 +++-- src/services/auth/.gitignore | 2 +- src/services/auth/src/index.ts | 5 ++++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/render-build-deploy.yml b/.github/workflows/render-build-deploy.yml index 3f01807..8487cec 100644 --- a/.github/workflows/render-build-deploy.yml +++ b/.github/workflows/render-build-deploy.yml @@ -26,7 +26,6 @@ jobs: - name: Generate Public/Private Keys for JWT auth functionality run: | - mkdir certs openssl genrsa -out ./certs/private.pem openssl rsa -in ./certs/private.pem -pubout -out ./certs/public.pem diff --git a/.gitignore b/.gitignore index b1dc9bb..a73d78b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Auth Keys -*.key *.pem certs/ -src/services/auth/certs/ +**/*.key **/*.pem +certs/ +!certs/.gitkeep # Logs *.log diff --git a/src/services/auth/.gitignore b/src/services/auth/.gitignore index 835f44d..769437f 100644 --- a/src/services/auth/.gitignore +++ b/src/services/auth/.gitignore @@ -1,5 +1,5 @@ # Auth Keys -*.key *.pem certs/ +**/*.key **/*.pem # Logs *.log diff --git a/src/services/auth/src/index.ts b/src/services/auth/src/index.ts index 277bd9a..3f8eddc 100644 --- a/src/services/auth/src/index.ts +++ b/src/services/auth/src/index.ts @@ -5,12 +5,15 @@ import { requiredEnvVars } from './config/app-config'; import bodyParser from 'body-parser'; import { errorHandler } from './middleware/errorHandler'; import authRouter from './routes/routes'; +import path from 'path'; const app = express(); // Allow requests from any origin app.use(cors()); -const publicKey = fs.readFileSync('./certs/public.pem', 'utf8'); +const publicKeyFilePath = path.resolve(__dirname, '../certs/public.pem'); +console.log('Attempting to read private key from:', publicKeyFilePath); +const publicKey = fs.readFileSync(publicKeyFilePath, 'utf8'); app.get('/public-key', (req, res) => { res.json({ publicKey });