Skip to content

Commit

Permalink
Fix some small errors with environment variables (#207)
Browse files Browse the repository at this point in the history
  • Loading branch information
davenquinn committed May 25, 2024
1 parent 920c4cf commit e2d46be
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 7 deletions.
4 changes: 2 additions & 2 deletions packages/settings/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ export function getRuntimeConfig(
const activeEnv = typeof window === "undefined" ? "server" : "client";
if (import.meta.env.SSR) {
// We are running on the server, try to get directly from process.env
val = globalThis.environment?.[key];
val = process.env["VITE_" + key];
} else {
// We are running on the client and have access to window.env
val = window.env[key];
}
if (val === undefined) {
val = import.meta.env["VITE_" + key];
if (val !== undefined && import.meta.env.DEV) {
if (val !== undefined) {
console.warn(`Environment variable ${key} loaded statically`);
}
}
Expand Down
5 changes: 4 additions & 1 deletion server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ const flavors = [

// Synthesize the config from the environment at runtime
const environment = synthesizeConfigFromEnvironment();
globalThis.environment = environment;

async function startServer() {
const app = express();
Expand All @@ -44,6 +43,10 @@ async function startServer() {
// (In dev, Vite's middleware serves our static assets.)
const sirv = (await import("sirv")).default;
app.use(sirv(`${root}/dist/client`));
// Special case for cesium files at /cesium prefix
// These should be copied into the client bundle but are not right now.
// Ideally we'd be able to remove this fix.
app.use("/cesium", sirv(`${root}/dist/cesium`));
} else {
// We instantiate Vite's development server and integrate its middleware to our server.
// ⚠️ We instantiate it only in development. (It isn't needed in production and it
Expand Down
4 changes: 0 additions & 4 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ const aliasedModules = [

const gitEnv = revisionInfo(pkg, "https://github.com/UW-Macrostrat/web");
// prefix with VITE_ to make available to client

for (const [key, value] of Object.entries(gitEnv)) {
process.env["VITE_" + key] = value;
}
Expand Down Expand Up @@ -66,9 +65,6 @@ const config: UserConfig = {
sourcemap: true,
},
define: {
"process.env": {
NODE_DEBUG: false,
},
// Cesium base URL
CESIUM_BASE_URL: JSON.stringify("/cesium"),
},
Expand Down

0 comments on commit e2d46be

Please sign in to comment.