Skip to content

Commit

Permalink
chore: do not fail when cow analytics db vars are not set
Browse files Browse the repository at this point in the history
  • Loading branch information
shoom3301 committed Dec 3, 2024
1 parent 7e86f4a commit 503e839
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions apps/api/src/app/plugins/orm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,24 @@ import fp from 'fastify-plugin';
import { PoolInfo } from '../data/poolInfo';

export default fp(async function (fastify: FastifyInstance) {
fastify.register(typeORMPlugin, {
const dbParams = {
host: fastify.config.COW_ANALYTICS_DATABASE_HOST,
port: Number(fastify.config.COW_ANALYTICS_DATABASE_PORT),
type: 'postgres',
database: fastify.config.COW_ANALYTICS_DATABASE_NAME,
username: fastify.config.COW_ANALYTICS_DATABASE_USERNAME,
password: fastify.config.COW_ANALYTICS_DATABASE_PASSWORD,
}

const dbParamsAreInvalid = Object.values(dbParams).some((v) => Number.isNaN(v) || v === undefined);

if (dbParamsAreInvalid) {
console.error('Invalid CoW Analytics database parameters, please check COW_ANALYTICS_* env vars');
return
}

fastify.register(typeORMPlugin, {
...dbParams,
type: 'postgres',
entities: [PoolInfo],
ssl: true,
extra: {
Expand Down

0 comments on commit 503e839

Please sign in to comment.