Skip to content

Commit 40c224e

Browse files
committed
feat: update frontend and backend for deployment with CORS fixes
1 parent 888819c commit 40c224e

File tree

3 files changed

+15
-21
lines changed

3 files changed

+15
-21
lines changed

apps/backend/.env.example

Lines changed: 0 additions & 12 deletions
This file was deleted.

apps/backend/api/index.ts

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import { Elysia } from "elysia";
66
const app = new Elysia()
77
.use(
88
cors({
9-
origin: process.env.CORS_ORIGIN || "*",
9+
origin: process.env.CORS_ORIGIN || "https://eventer-web-red.vercel.app",
1010
credentials: true,
1111
})
1212
)
@@ -32,14 +32,14 @@ export default async function handler(req: any, res: any) {
3232
path: req.url?.split("?")[0],
3333
});
3434

35-
// Set CORS headers
36-
res.setHeader("Access-Control-Allow-Origin", "*");
37-
res.setHeader("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE, OPTIONS");
38-
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
39-
40-
// Handle preflight requests
35+
// Let Elysia handle CORS and preflight entirely
4136
if (req.method === "OPTIONS") {
42-
res.status(200).end();
37+
const response = await app.handle(new Request("https://dummy", { method: "OPTIONS" }));
38+
res.status(response.status);
39+
for (const [key, value] of response.headers.entries()) {
40+
res.setHeader(key, value);
41+
}
42+
res.end();
4343
return;
4444
}
4545

apps/web/src/lib/client.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,10 @@ const getBackendUrl = () => {
2020
return `${window.location.protocol}//${window.location.hostname}:4000`;
2121
};
2222

23-
export const client = treaty<AppType>(getBackendUrl());
23+
export const client = treaty<AppType>(getBackendUrl(), {
24+
fetch: (input, init) =>
25+
fetch(input, {
26+
...init,
27+
credentials: "include", // ✅ Send cookies
28+
}),
29+
});

0 commit comments

Comments
 (0)