fix: fix client rewrite url

This commit is contained in:
Khairul Hidayat 2024-08-09 23:27:36 +07:00
parent 18b0f47c49
commit 22ea803add
3 changed files with 14 additions and 11 deletions

View File

@ -15,7 +15,7 @@
"db:push": "drizzle-kit push --config server/drizzle.config.ts", "db:push": "drizzle-kit push --config server/drizzle.config.ts",
"db:seed": "bun run server/db/seed.ts", "db:seed": "bun run server/db/seed.ts",
"dev": "concurrently \"npm run client:dev\" \"npm run server:dev\"", "dev": "concurrently \"npm run client:dev\" \"npm run server:dev\"",
"build": "npm run client:build && npm run server:build", "build": "npm run client:build",
"start": "NODE_ENV=production bun run server/main.ts", "start": "NODE_ENV=production bun run server/main.ts",
"start:worker": "NODE_ENV=production bun run server/queue-worker.ts" "start:worker": "NODE_ENV=production bun run server/queue-worker.ts"
}, },

View File

@ -19,20 +19,27 @@ app.onError((err, c) => {
// Allow all origin on development // Allow all origin on development
if (__DEV) { if (__DEV) {
app.use(cors({ origin: "*" })); app.use(cors({ origin: "*" }));
} else {
app.use(httpLogger());
} }
// Health check // Health check
app.get("/health", (c) => c.text("OK")); app.get("/health", (c) => c.text("OK"));
// Serve prod client app
if (__PROD) {
app.use(httpLogger());
app.use(serveStatic({ root: "./dist/client" }));
}
// API router // API router
app.route("/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({ Bun.serve({
fetch: app.fetch, fetch: app.fetch,
hostname: HOST, hostname: HOST,

View File

@ -11,10 +11,6 @@ export default defineConfig({
"@server": path.resolve(__dirname, "./server"), "@server": path.resolve(__dirname, "./server"),
}, },
}, },
build: {
outDir: "dist/client",
emptyOutDir: true,
},
server: { server: {
proxy: { proxy: {
"/api": process.env.API_BASEURL || "http://127.0.0.1:5589", "/api": process.env.API_BASEURL || "http://127.0.0.1:5589",