-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use env file instead of process.env everywhere
- Loading branch information
Showing
17 changed files
with
144 additions
and
53 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const { z } = require("zod"); | ||
|
||
const buildSchema = z.object({ | ||
// Used to display a mention of the current deployment in development mode | ||
DEPLOYMENT: z.string().optional(), | ||
CURRENT_PERIOD: z.string().default("2025"), | ||
FIRST_PERIOD: z.string().default("2009"), | ||
VERSION: z.string().optional(), | ||
}); | ||
|
||
// Define the schema for server-side variables | ||
const serverSchema = z.object({ | ||
// Gever document download | ||
EIAM_CERTIFICATE_CONTENT: z.string().optional(), | ||
EIAM_CERTIFICATE_PASSWORD: z.string(), | ||
EIAM_CERTIFICATE_PATH: z.string(), | ||
GEVER_BINDING_IPSTS: z.string(), | ||
GEVER_BINDING_RPSTS: z.string(), | ||
GEVER_BINDING_SERVICE: z.string(), | ||
DEBUG_DOWNLOAD_SECRET: z | ||
.string() | ||
.default("GqQF$t$Fm^oddinivkY8TT8F^kRuRUJ$NJ5Jt%vQ"), | ||
|
||
ELCOM_ENV: z.string(), | ||
|
||
// Gitlab as CMS | ||
GITLAB_WIKI_TOKEN: z.string(), | ||
GITLAB_WIKI_URL: z.string(), | ||
|
||
// Tracking | ||
MATOMO_ID: z.string(), | ||
|
||
// Apollo plugin | ||
METRICS_PLUGIN_ENABLED: z.string(), | ||
|
||
NODE_ENV: z.string(), | ||
|
||
// Sparql | ||
SPARQL_EDITOR: z.string().optional(), | ||
SPARQL_ENDPOINT: z.string().default("https://test.lindas.admin.ch/query"), | ||
}); | ||
|
||
module.exports = { | ||
serverEnv: | ||
typeof window !== "undefined" ? serverSchema.parse(process.env) : null, | ||
|
||
// Need to inline variables here so that they are replaced at build time | ||
buildEnv: buildSchema.parse({ | ||
DEPLOYMENT: process.env.DEPLOYMENT, | ||
CURRENT_PERIOD: process.env.CURRENT_PERIOD, | ||
FIRST_PERIOD: process.env.CURRENT_PERIOD, | ||
VERSION: process.env.VERSION, | ||
}), | ||
|
||
buildSchema: buildSchema, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
function assert(predicate: boolean, message: string): asserts predicate { | ||
if (!predicate) { | ||
throw new Error(message); | ||
} | ||
} | ||
|
||
export default assert; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,9 @@ | ||
import { NextApiRequest, NextApiResponse } from "next"; | ||
|
||
import { serverEnv } from "src/domain/env"; | ||
import assert from "src/lib/assert"; | ||
|
||
export default async (req: NextApiRequest, res: NextApiResponse) => { | ||
res.json({ matomoId: process.env.MATOMO_ID }); | ||
assert(!!serverEnv, "serverEnv is not defined"); | ||
res.json({ matomoId: serverEnv.MATOMO_ID }); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.