Skip to content

Commit

Permalink
fix: allow empty NODE_ENV for prometheus (#73)
Browse files Browse the repository at this point in the history
* fix: allow empty NODE_ENV for prometheus

* chore: move helpers to avoid env errors

* fix: vercel ci master build
  • Loading branch information
rafaelcr committed May 15, 2023
1 parent 09eaa26 commit e8dcd3b
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/vercel.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ env:
on:
push:
branches:
- develop
- master
- beta
- develop
pull_request:

jobs:
Expand Down
3 changes: 2 additions & 1 deletion src/api/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { PgStore } from '../pg/pg-store';
import { SatRoutes } from './routes/sats';
import { StatusRoutes } from './routes/status';
import FastifyMetrics from 'fastify-metrics';
import { isProdEnv } from './util/helpers';

export const Api: FastifyPluginAsync<
Record<never, never>,
Expand All @@ -26,7 +27,7 @@ export async function buildApiServer(args: { db: PgStore }) {
}).withTypeProvider<TypeBoxTypeProvider>();

fastify.decorate('db', args.db);
if (process.env.NODE_ENV === 'production') {
if (isProdEnv) {
await fastify.register(FastifyMetrics);
}
await fastify.register(FastifyCors);
Expand Down
8 changes: 8 additions & 0 deletions src/api/util/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,14 @@
import { DbFullyLocatedInscriptionResult, DbLocation } from '../../pg/types';
import { InscriptionLocationResponse, InscriptionResponseType } from '../schemas';

export const isDevEnv = process.env.NODE_ENV === 'development';
export const isTestEnv = process.env.NODE_ENV === 'test';
export const isProdEnv =
process.env.NODE_ENV === 'production' ||
process.env.NODE_ENV === 'prod' ||
!process.env.NODE_ENV ||
(!isTestEnv && !isDevEnv);

export const DEFAULT_API_LIMIT = 20;

export function parseDbInscriptions(
Expand Down
8 changes: 0 additions & 8 deletions src/env.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
import { Static, Type } from '@sinclair/typebox';
import envSchema from 'env-schema';

export const isDevEnv = process.env.NODE_ENV === 'development';
export const isTestEnv = process.env.NODE_ENV === 'test';
export const isProdEnv =
process.env.NODE_ENV === 'production' ||
process.env.NODE_ENV === 'prod' ||
!process.env.NODE_ENV ||
(!isTestEnv && !isDevEnv);

const schema = Type.Object({
/**
* Run mode for this service. Allows you to control how the API runs, typically in an auto-scaled
Expand Down

0 comments on commit e8dcd3b

Please sign in to comment.