Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Commit

Permalink
fix(env): rename NODE_ENV to API_ENV to avoid Render overrides (#536)
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianAndersen authored Aug 8, 2024
1 parent a780a71 commit 53f926a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"prettier": "prettier --write . --ignore-path=.gitignore",
"prettier:check": "prettier --check . --ignore-path=.gitignore",
"lint": "eslint .",
"test": "NODE_ENV=test mocha \"src/**/*.spec.ts\"",
"test": "API_ENV=test mocha \"src/**/*.spec.ts\"",
"load_fixtures": "mongodb-fixtures rebuild -u mongodb://127.0.0.1:27017/test"
},
"license": "ISC",
Expand Down
2 changes: 1 addition & 1 deletion src/config/api-path.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export class ApiPath {
private readonly baseHost: string;

constructor() {
if (assertEnv(BlEnvironment.NODE_ENV) === "production") {
if (assertEnv(BlEnvironment.API_ENV) === "production") {
this.baseHost = APP_CONFIG.path.host;
} else {
this.baseHost = APP_CONFIG.path.local.host;
Expand Down
4 changes: 2 additions & 2 deletions src/config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { isNullish } from "../helper/typescript-helpers";
export enum BlEnvironment {
PORT = "PORT",
SERVER_PATH = "SERVER_PATH",
NODE_ENV = "NODE_ENV",
API_ENV = "API_ENV",
LOG_LEVEL = "LOG_LEVEL",
URI_WHITELIST = "URI_WHITELIST",
ACCESS_TOKEN_SECRET = "ACCESS_TOKEN_SECRET",
Expand Down Expand Up @@ -43,7 +43,7 @@ const testPlaceHolders: {
*/
export function assertEnv(key: BlEnvironment): string {
const value = process.env[key];
if (process.env[BlEnvironment.NODE_ENV] === "test")
if (process.env[BlEnvironment.API_ENV] === "test")
return testPlaceHolders[key] ?? "placeholder";
if (isNullish(value)) {
throw new BlError(`${key} is a required environment variable`).code(200);
Expand Down
4 changes: 2 additions & 2 deletions src/logger/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const logger = createLogger({
format: format.combine(
format.printf((info) => {
const colorizer = format.colorize();
const nodeEnv = assertEnv(BlEnvironment.NODE_ENV);
const nodeEnv = assertEnv(BlEnvironment.API_ENV);
if (nodeEnv === "production" || nodeEnv === "dev") {
return `${info.level} ${info.message}`;
}
Expand All @@ -31,7 +31,7 @@ export const logger = createLogger({
);
}),
format.colorize({
all: assertEnv(BlEnvironment.NODE_ENV) !== "production",
all: assertEnv(BlEnvironment.API_ENV) !== "production",
}),
),
transports: [
Expand Down
6 changes: 3 additions & 3 deletions src/server/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ export class Server {
};

this.app.use(
assertEnv(BlEnvironment.NODE_ENV) === "production"
assertEnv(BlEnvironment.API_ENV) === "production"
? cors(corsConfig)
: cors(),
);
Expand All @@ -132,7 +132,7 @@ export class Server {
if (
!(
req.url.includes("auth") &&
assertEnv(BlEnvironment.NODE_ENV) === "production"
assertEnv(BlEnvironment.API_ENV) === "production"
)
) {
let body: string;
Expand All @@ -151,7 +151,7 @@ export class Server {
this.app.get("*", (req, res, next) => {
if (
req.headers["x-forwarded-proto"] !== "https" &&
assertEnv(BlEnvironment.NODE_ENV) === "production"
assertEnv(BlEnvironment.API_ENV) === "production"
) {
res.redirect("https://" + req.hostname + req.url);
} else {
Expand Down

0 comments on commit 53f926a

Please sign in to comment.