Skip to content

Commit 329e14b

Browse files
committed
fix: improve CORS headers handling and format request interceptor for better readability
1 parent b65ba5d commit 329e14b

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

api/app.js

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ app.use(
4141
"X-Forwarded-For",
4242
"X-Real-IP",
4343
"User-Agent",
44-
"Referer"
44+
"Referer",
4545
],
4646
exposedHeaders: ["Content-Length", "Content-Type"],
4747
maxAge: 86400, // 24 hours
@@ -62,8 +62,12 @@ app.use("/api", publicLimiter);
6262
// Specific handler for deliveries preflight (must come before general options handler)
6363
app.options("/api/deliveries", (req, res) => {
6464
res.header("Access-Control-Allow-Origin", req.headers.origin || "*");
65-
res.header("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,PATCH,OPTIONS");
66-
res.header("Access-Control-Allow-Headers",
65+
res.header(
66+
"Access-Control-Allow-Methods",
67+
"GET,POST,PUT,DELETE,PATCH,OPTIONS"
68+
);
69+
res.header(
70+
"Access-Control-Allow-Headers",
6771
"Content-Type,Authorization,Accept,Origin,X-Requested-With,x-request-timeout,X-Request-Timeout,Access-Control-Allow-Headers,Access-Control-Allow-Origin,Cache-Control,Pragma,X-HTTP-Method-Override,X-Forwarded-For,X-Real-IP,User-Agent,Referer"
6872
);
6973
res.header("Access-Control-Allow-Credentials", "true");

client/src/services/api.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ api.interceptors.request.use(
6565
config.headers?.set?.("Authorization", `Bearer ${token}`);
6666

6767
// Or fallback for older Axios (still safe)
68-
(config.headers as Record<string, string>)["Authorization"] = `Bearer ${token}`;
68+
(config.headers as Record<string, string>)[
69+
"Authorization"
70+
] = `Bearer ${token}`;
6971
}
7072
return config;
7173
},

0 commit comments

Comments
 (0)