fix admin UI serve

This commit is contained in:
Grant 2024-05-28 21:02:00 -06:00
parent f567e7abd1
commit 6308992e02
5 changed files with 11 additions and 9 deletions

View File

@ -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 ---

View File

@ -31,7 +31,7 @@ const router = createBrowserRouter(
},
],
{
basename: import.meta.env.VITE_APP_ROOT,
basename: __APP_ROOT__,
}
);

View File

@ -1 +1,3 @@
/// <reference types="vite/client" />
declare const __APP_ROOT__: string;

View File

@ -15,4 +15,7 @@ export default defineConfig({
include: "**/*.{jsx,tsx}",
}),
],
define: {
__APP_ROOT__: JSON.stringify(process.env.APP_ROOT),
},
});

View File

@ -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);
});
}