From 07f915f9fe1bbb9ea790f7af80a82c1ba3f2b933 Mon Sep 17 00:00:00 2001 From: Franco NG Date: Tue, 6 Feb 2024 15:33:23 +0100 Subject: [PATCH] Updated .env and README --- packages/claim-backend/.env.example | 2 ++ packages/claim-backend/README.md | 19 +++++++++++-------- packages/claim-backend/src/db.ts | 9 +++++++++ packages/claim-backend/src/index.ts | 10 +++++++--- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/packages/claim-backend/.env.example b/packages/claim-backend/.env.example index f7a3ace..8a96dd7 100644 --- a/packages/claim-backend/.env.example +++ b/packages/claim-backend/.env.example @@ -1,7 +1,9 @@ +BACKEND_HOST=0.0.0.0 BACKEND_PORT=3000 DB_PORT=5432 DB_HOST=127.0.0.1 DB_DATABASE=claim-backend DB_USERNAME=claim-backend DB_PASSWORD=let-me-in +DB_SSLMODE=true MERKLE_TREE_PATH=/Users/lisk-token-claim/data/merkle-tree-result-detailed.json \ No newline at end of file diff --git a/packages/claim-backend/README.md b/packages/claim-backend/README.md index d55ed12..f81e4ad 100644 --- a/packages/claim-backend/README.md +++ b/packages/claim-backend/README.md @@ -9,14 +9,17 @@ This library supplies leaf details to frontend. It also stores partial signature ## .env Params -| param | Description | Required | -| ---------------- | -------------------------------------------------------- | -------- | -| BACKEND_PORT | Port used by backend (Default: 3000) | false | -| DB_PORT | Port used by PostSQL DB (Default: 5432) | false | -| DB_DATABASE | Name of Database of PostSQL DB (Default: claim-backend) | false | -| DB_USERNAME | Username of PostSQL DB (Default: claim-backend) | false | -| DB_PASSWORD | Password of Database of PostSQL DB (Default: let-me-in) | false | -| MERKLE_TREE_PATH | Path merkle-tree-details.json, generated by Tree Builder | true | +| param | Description | Required | +| ---------------- | ---------------------------------------------------------- | -------- | +| BACKEND_HOST | IP used by backend (Default: 127.0.0.1) | false | +| BACKEND_PORT | Port used by backend (Default: 3000) | false | +| DB_PORT | Port used by PostgreSQL DB (Default: 5432) | false | +| DB_HOST | Host used by PostgreSQL DB (Default: 127.0.0.1) | false | +| DB_DATABASE | Name of Database of PostgreSQL DB (Default: claim-backend) | false | +| DB_USERNAME | Username of PostgreSQL DB (Default: claim-backend) | false | +| DB_PASSWORD | Password of Database of PostgreSQL DB (Default: let-me-in) | false | +| DB_SSLMODE | A flag to turn on SSL Connection on DB (Default: false) | false | +| MERKLE_TREE_PATH | Path merkle-tree-details.json, generated by Tree Builder | true | ## Run diff --git a/packages/claim-backend/src/db.ts b/packages/claim-backend/src/db.ts index 86c1cdc..3f84e4b 100644 --- a/packages/claim-backend/src/db.ts +++ b/packages/claim-backend/src/db.ts @@ -15,6 +15,15 @@ class DB { password: process.env.DB_PASSWORD || 'let-me-in', models: [__dirname + '/models/*.model.ts'], port: Number(process.env.DB_PORT) || 5432, + dialectOptions: + process.env.DB_SSLMODE === 'true' + ? { + ssl: { + require: true, + rejectUnauthorized: false, + }, + } + : {}, }); this.sequelize.addModels(this.models); } diff --git a/packages/claim-backend/src/index.ts b/packages/claim-backend/src/index.ts index 0e0846e..15d2736 100644 --- a/packages/claim-backend/src/index.ts +++ b/packages/claim-backend/src/index.ts @@ -7,7 +7,8 @@ import { submitMultisig } from './controllers/submit-multisig'; import { checkEligibility } from './controllers/check-eligibility'; dotenv.config(); -const PORT = process.env.BACKEND_PORT || 3000; +const HOST = process.env.BACKEND_HOST || '127.0.0.1'; +const PORT = Number(process.env.BACKEND_PORT) || 3000; const server = new JSONRPCServer(); void (async () => { @@ -21,6 +22,9 @@ void (async () => { server.addMethod('checkEligibility', checkEligibility); server.addMethod('submitMultisig', submitMultisig); + // For Health Check + app.get('/', (_, res) => res.send('OK')); + app.post('/rpc', (req, res) => { const jsonRPCRequest = req.body; @@ -36,8 +40,8 @@ void (async () => { const db = new DB(); await db.sync(); - app.listen(PORT, () => { - console.info(`Claim Backend running at port ${PORT}`); + app.listen(PORT, HOST, () => { + console.info(`Claim Backend running at ${HOST}:${PORT}`); }); } })();