diff --git a/Dockerfile b/Dockerfile index 2bd91d1..0c9e0a5 100644 --- a/Dockerfile +++ b/Dockerfile @@ -55,6 +55,7 @@ RUN npm -w packages/client run build # --- build admin --- +ENV APP_ROOT /admin RUN npm -w packages/admin run build # --- build server --- diff --git a/packages/admin/src/main.tsx b/packages/admin/src/main.tsx index ee14eb1..0a57ac3 100644 --- a/packages/admin/src/main.tsx +++ b/packages/admin/src/main.tsx @@ -31,7 +31,7 @@ const router = createBrowserRouter( }, ], { - basename: import.meta.env.VITE_APP_ROOT, + basename: __APP_ROOT__, } ); diff --git a/packages/admin/src/vite-env.d.ts b/packages/admin/src/vite-env.d.ts index 11f02fe..3a103a0 100644 --- a/packages/admin/src/vite-env.d.ts +++ b/packages/admin/src/vite-env.d.ts @@ -1 +1,3 @@ /// + +declare const __APP_ROOT__: string; diff --git a/packages/admin/vite.config.ts b/packages/admin/vite.config.ts index 5528bdb..33d602e 100644 --- a/packages/admin/vite.config.ts +++ b/packages/admin/vite.config.ts @@ -15,4 +15,7 @@ export default defineConfig({ include: "**/*.{jsx,tsx}", }), ], + define: { + __APP_ROOT__: JSON.stringify(process.env.APP_ROOT), + }, }); diff --git a/packages/server/src/lib/Express.ts b/packages/server/src/lib/Express.ts index cd7a042..62632a4 100644 --- a/packages/server/src/lib/Express.ts +++ b/packages/server/src/lib/Express.ts @@ -69,17 +69,13 @@ export class ExpressServer { // client is needing to serve Logger.info( "Serving admin UI at /admin using root " + - path.join(__dirname, process.env.SERVE_ADMIN) - ); - const assetsDir = path.join(__dirname, process.env.SERVE_ADMIN, "assets"); - const indexFile = path.join( - __dirname, - process.env.SERVE_ADMIN, - "index.html" + path.join(process.env.SERVE_ADMIN) ); + const assetsDir = path.join(process.env.SERVE_ADMIN, "assets"); + const indexFile = path.join(process.env.SERVE_ADMIN, "index.html"); this.app.use("/admin/assets", express.static(assetsDir)); - this.app.use("/admin/*", (req, res) => { + this.app.use("/admin*", (req, res) => { res.sendFile(indexFile); }); }