fix: fix client rewrite url

This commit is contained in:
2024-08-09 23:27:36 +07:00
parent 18b0f47c49
commit 22ea803add
3 changed files with 14 additions and 11 deletions
+13 -6
View File
@@ -19,20 +19,27 @@ app.onError((err, c) => {
// Allow all origin on development
if (__DEV) {
app.use(cors({ origin: "*" }));
} else {
app.use(httpLogger());
}
// Health check
app.get("/health", (c) => c.text("OK"));
// Serve prod client app
if (__PROD) {
app.use(httpLogger());
app.use(serveStatic({ root: "./dist/client" }));
}
// API router
app.route("/api", router);
// Serve prod client app
if (__PROD) {
const CLIENT_DIST_DIR = "./dist";
app.use(serveStatic({ root: CLIENT_DIST_DIR }));
app.get("*", async (c) => {
const index = Bun.file(CLIENT_DIST_DIR + "/index.html");
const content = await index.text();
return c.html(content);
});
}
Bun.serve({
fetch: app.fetch,
hostname: HOST,