Skip to content

Commit

Permalink
cache & cors header
Browse files Browse the repository at this point in the history
  • Loading branch information
naltatis committed Jun 11, 2024
1 parent d625f18 commit 715e9cb
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
10 changes: 10 additions & 0 deletions src/server.cloudflare.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,18 @@ import manifest from "__STATIC_CONTENT_MANIFEST";

const app = createServer();

const setCacheAndCors = (req, res, next) => {
res.setHeader("Cache-Control", "public, max-age=3600"); // 1 hour cache
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,DELETE,OPTIONS");
res.setHeader("Access-Control-Allow-Headers", "Content-Type, Authorization");
next();
};

app.use("/cdn/*", setCacheAndCors);
app.use("/cdn/*", serveStatic({ root: "./", manifest }));
["explore", "decide", "checkout"].forEach((team) => {
app.use(`/${team}/static/*`, setCacheAndCors);
app.use(`/${team}/static/*`, serveStatic({ root: `./`, manifest }));
});

Expand Down
10 changes: 1 addition & 9 deletions wrangler.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,4 @@ main = "src/server.cloudflare.js"
compatibility_date = "2024-03-12"

[site]
bucket = "./public"

[[site.headers]]
for = "*"
[site.headers.values]
Cache-Control = "public, max-age=3600"
Access-Control-Allow-Origin = "*"
Access-Control-Allow-Methods = "GET, POST, OPTIONS"
Access-Control-Allow-Headers = "*"
bucket = "./public"

0 comments on commit 715e9cb

Please sign in to comment.