Skip to content

Commit

Permalink
Fix public key path to read file contents dynamically by generated JS…
Browse files Browse the repository at this point in the history
… files after build

- Substitute the `mkdir` step from deployment actions by keeping track of the certs dir.
  • Loading branch information
ahmadSaeedGoda committed Mar 22, 2024
1 parent 3b7a147 commit d0d7a5d
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 5 deletions.
1 change: 0 additions & 1 deletion .github/workflows/render-build-deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Auth Keys
*.key *.pem certs/
src/services/auth/certs/
**/*.key **/*.pem
certs/
!certs/.gitkeep

# Logs
*.log
Expand Down
2 changes: 1 addition & 1 deletion src/services/auth/.gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Auth Keys
*.key *.pem certs/
**/*.key **/*.pem

# Logs
*.log
Expand Down
5 changes: 4 additions & 1 deletion src/services/auth/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 });
Expand Down

0 comments on commit d0d7a5d

Please sign in to comment.