optimize the way we consume env variables

This commit is contained in:
EGOIST
2022-05-06 21:18:25 +08:00
parent f1428397f2
commit 2ee4f3197d
23 changed files with 120 additions and 88 deletions
+7 -8
View File
@@ -1,13 +1,12 @@
import { type RequestHandler } from "express"
import {
FLY_REGION,
IS_PRIMARY_REGION,
PRIMARY_REGION,
} from "~/lib/config.server"
import { IS_PROD } from "~/lib/config.shared"
import { IS_PROD } from "~/lib/constants"
import { getServerEnv, isPrimaryRegion } from "~/lib/env"
const PRIMARY_REGION = getServerEnv("PRIMARY_REGION")
const FLY_REGION = getServerEnv("FLY_REGION")
export const setFlyRegionHeader: RequestHandler = (req, res, next) => {
res.setHeader("x-fly-region", FLY_REGION || "unknown")
res.setHeader("x-fly-region", PRIMARY_REGION || "unknown")
next()
}
@@ -17,7 +16,7 @@ export const getReplayResponse: RequestHandler = (req, res, next) => {
if (
!IS_PROD ||
["GET", "OPTIONS", "HEAD"].includes(method) ||
IS_PRIMARY_REGION
isPrimaryRegion()
) {
return next()
}