Skip to content

Commit

Permalink
Updated .env and README
Browse files Browse the repository at this point in the history
  • Loading branch information
Phanco committed Feb 6, 2024
1 parent 7bf8f22 commit 07f915f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
2 changes: 2 additions & 0 deletions packages/claim-backend/.env.example
Original file line number Diff line number Diff line change
@@ -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
19 changes: 11 additions & 8 deletions packages/claim-backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
9 changes: 9 additions & 0 deletions packages/claim-backend/src/db.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
10 changes: 7 additions & 3 deletions packages/claim-backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -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;

Expand All @@ -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}`);
});
}
})();

0 comments on commit 07f915f

Please sign in to comment.