From d1cba263841f597f198d096b36b88b1ae0d25262 Mon Sep 17 00:00:00 2001 From: keiya sasaki Date: Thu, 6 Jul 2023 13:28:43 +0900 Subject: [PATCH] chore(web): allow reearth_config.json to be set remotely for local development (#559) --- web/vite.config.ts | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/web/vite.config.ts b/web/vite.config.ts index d6d1ccf1a6..97efd8ad65 100644 --- a/web/vite.config.ts +++ b/web/vite.config.ts @@ -78,20 +78,27 @@ function config(): Plugin { return { name: "reearth-config", async configureServer(server) { + const envs = loadEnv( + server.config.mode, + server.config.envDir ?? process.cwd(), + server.config.envPrefix, + ); + const remoteReearthConfig = envs.REEARTH_WEB_CONFIG_URL + ? await (await fetch(envs.REEARTH_WEB_CONFIG_URL)).json() + : {}; const configRes = JSON.stringify( { + ...remoteReearthConfig, api: "http://localhost:8080/api", published: "/published.html?alias={}", // If Cesium version becomes outdated, you can set the Ion token as an environment variables here. // ex: `CESIUM_ION_ACCESS_TOKEN="ION_TOKEN" yarn start` // ref: https://github.com/CesiumGS/cesium/blob/main/packages/engine/Source/Core/Ion.js#L6-L7 - cesiumIonAccessToken: process.env.CESIUM_ION_ACCESS_TOKEN, + ...(process.env.CESIUM_ION_ACCESS_TOKEN + ? { cesiumIonAccessToken: process.env.CESIUM_ION_ACCESS_TOKEN } + : {}), ...readEnv("REEARTH_WEB", { - source: loadEnv( - server.config.mode, - server.config.envDir ?? process.cwd(), - server.config.envPrefix, - ), + source: envs, }), ...loadJSON("./reearth-config.json"), },