Skip to content

Commit 715e9cb

Browse files
committed
cache & cors header
1 parent d625f18 commit 715e9cb

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

src/server.cloudflare.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,18 @@ import manifest from "__STATIC_CONTENT_MANIFEST";
44

55
const app = createServer();
66

7+
const setCacheAndCors = (req, res, next) => {
8+
res.setHeader("Cache-Control", "public, max-age=3600"); // 1 hour cache
9+
res.setHeader("Access-Control-Allow-Origin", "*");
10+
res.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
11+
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
12+
next();
13+
};
14+
15+
app.use("/cdn/*", setCacheAndCors);
716
app.use("/cdn/*", serveStatic({ root: "./", manifest }));
817
["explore", "decide", "checkout"].forEach((team) => {
18+
app.use(`/${team}/static/*`, setCacheAndCors);
919
app.use(`/${team}/static/*`, serveStatic({ root: `./`, manifest }));
1020
});
1121

wrangler.toml

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,4 @@ main = "src/server.cloudflare.js"
33
compatibility_date = "2024-03-12"
44

55
[site]
6-
bucket = "./public"
7-
8-
[[site.headers]]
9-
for = "*"
10-
[site.headers.values]
11-
Cache-Control = "public, max-age=3600"
12-
Access-Control-Allow-Origin = "*"
13-
Access-Control-Allow-Methods = "GET, POST, OPTIONS"
14-
Access-Control-Allow-Headers = "*"
6+
bucket = "./public"

0 commit comments

Comments
 (0)