Skip to content

Commit

Permalink
fix(cloudflare): routes.json order (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderniebuhr committed Apr 24, 2024
1 parent 87eb46c commit e08cd4c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
5 changes: 5 additions & 0 deletions .changeset/thirty-apricots-marry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@astrojs/cloudflare': patch
---

Fixes an issue where redirect rules where not excluded from routing due to ordering issues
8 changes: 4 additions & 4 deletions packages/cloudflare/src/utils/generate-routes-json.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ export async function createRoutesFile(
);
excludePaths.push(assetsPath);

for (const redirect of redirects) {
excludePaths.push(segmentsToCfSyntax(redirect, _config));
}

if (existsSync(fileURLToPath(_config.publicDir))) {
const staticFiles = await glob(`${fileURLToPath(_config.publicDir)}/**/*`, {
cwd: fileURLToPath(_config.publicDir),
Expand All @@ -190,10 +194,6 @@ export async function createRoutesFile(
}
}

for (const redirect of redirects) {
excludePaths.push(segmentsToCfSyntax(redirect, _config));
}

let hasPrerendered404 = false;
for (const route of routes) {
const convertedPath = segmentsToCfSyntax(route.segments, _config);
Expand Down
8 changes: 4 additions & 4 deletions packages/cloudflare/test/routes-json.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ describe('_routes.json generation', () => {
assert.deepEqual(routes, {
version: 1,
include: ['/_image', '/a/*'],
exclude: ['/_astro/*', '/public.txt', '/redirectme', '/a', '/a/redirect', '/404', '/b'],
exclude: ['/_astro/*', '/redirectme', '/public.txt', '/a', '/a/redirect', '/404', '/b'],
});
});
});
Expand All @@ -48,7 +48,7 @@ describe('_routes.json generation', () => {
assert.deepEqual(routes, {
version: 1,
include: ['/*'],
exclude: ['/_astro/*', '/public.txt', '/redirectme', '/a/redirect'],
exclude: ['/_astro/*', '/redirectme', '/public.txt', '/a/redirect'],
});
});
});
Expand Down Expand Up @@ -102,7 +102,7 @@ describe('_routes.json generation', () => {
assert.deepEqual(routes, {
version: 1,
include: ['/_image', '/a/*', '/another'],
exclude: ['/_astro/*', '/public.txt', '/redirectme', '/a', '/a/redirect', '/404', '/b'],
exclude: ['/_astro/*', '/redirectme', '/public.txt', '/a', '/a/redirect', '/404', '/b'],
});
});
});
Expand Down Expand Up @@ -134,8 +134,8 @@ describe('_routes.json generation', () => {
include: ['/_image', '/a/*'],
exclude: [
'/_astro/*',
'/public.txt',
'/redirectme',
'/public.txt',
'/a',
'/a/redirect',
'/404',
Expand Down

0 comments on commit e08cd4c

Please sign in to comment.