Skip to content

Commit 8927800

Browse files
authored
fix(cloudflare-module): output _headers file to correct directory (#3517)
1 parent dc4f1a9 commit 8927800

2 files changed

Lines changed: 13 additions & 5 deletions

File tree

src/presets/cloudflare/preset.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ const cloudflarePages = defineNitroPreset(
6060
async compiled(nitro: Nitro) {
6161
await writeWranglerConfig(nitro, "pages");
6262
await writeCFRoutes(nitro);
63-
await writeCFHeaders(nitro);
63+
await writeCFHeaders(nitro, "output");
6464
await writeCFPagesRedirects(nitro);
6565
},
6666
},
@@ -93,7 +93,7 @@ const cloudflarePagesStatic = defineNitroPreset(
9393
}
9494
},
9595
async compiled(nitro: Nitro) {
96-
await writeCFHeaders(nitro);
96+
await writeCFHeaders(nitro, "output");
9797
await writeCFPagesRedirects(nitro);
9898
},
9999
},
@@ -160,7 +160,7 @@ const cloudflareModule = defineNitroPreset(
160160
},
161161
async compiled(nitro: Nitro) {
162162
await writeWranglerConfig(nitro, "module");
163-
await writeCFHeaders(nitro);
163+
await writeCFHeaders(nitro, "public");
164164

165165
await writeFile(
166166
resolve(nitro.options.output.dir, "package.json"),

src/presets/cloudflare/utils.ts

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,16 @@ function comparePaths(a: string, b: string) {
105105
return a.split("/").length - b.split("/").length || a.localeCompare(b);
106106
}
107107

108-
export async function writeCFHeaders(nitro: Nitro) {
109-
const headersPath = join(nitro.options.output.dir, "_headers");
108+
export async function writeCFHeaders(
109+
nitro: Nitro,
110+
outdir: "public" | "output"
111+
) {
112+
const headersPath = join(
113+
outdir === "public"
114+
? nitro.options.output.publicDir
115+
: nitro.options.output.dir,
116+
"_headers"
117+
);
110118
const contents = [];
111119

112120
const rules = Object.entries(nitro.options.routeRules).sort(

0 commit comments

Comments
 (0)