fix: env in dev:worker
This commit is contained in:
+1
-1
@@ -19,7 +19,7 @@
|
||||
"cypress:verify": "cypress verify",
|
||||
"test:e2e": "start-server-and-test dev http://localhost:4321 cypress:run",
|
||||
"test:e2e:ci": "NODE_TLS_REJECT_UNAUTHORIZED=0 start-server-and-test preview:ci http://localhost:4321 cypress:run",
|
||||
"dev:worker": "npx wrangler dev --port 4321 --ip 0.0.0.0"
|
||||
"dev:worker": "npx astro build && npx wrangler dev --port 4321 --ip 0.0.0.0"
|
||||
},
|
||||
"dependencies": {
|
||||
"@astrojs/cloudflare": "^12.6.0",
|
||||
|
||||
+16
-3
@@ -1,12 +1,25 @@
|
||||
import dotenv from "dotenv";
|
||||
|
||||
let dotenvLoaded = false;
|
||||
|
||||
function loadEnv() {
|
||||
if (typeof process !== "undefined" && !dotenvLoaded) {
|
||||
dotenv.config();
|
||||
dotenvLoaded = true;
|
||||
}
|
||||
}
|
||||
|
||||
export function getEnvVariable(key: string): string {
|
||||
loadEnv();
|
||||
|
||||
const envVar = import.meta.env?.[key] ?? process.env?.[key];
|
||||
|
||||
if (envVar === undefined) {
|
||||
throw new Error(`Missing env variable: ${key} is not defined`);
|
||||
throw new Error(`Missing env variable: ${key}`);
|
||||
}
|
||||
|
||||
if (envVar === "") {
|
||||
throw new Error(`Env variable: ${key} is defined but empty`);
|
||||
if (envVar === null || envVar === "") {
|
||||
throw new Error(`Env variable ${key} is empty`);
|
||||
}
|
||||
|
||||
return envVar;
|
||||
|
||||
Reference in New Issue
Block a user