Skip to content

Commit a9f607f

Browse files
meganemuraclaude
andauthored
fix(routing): serve static files that a rewrite points to (#512)
A rewrite to a static file returns 404 when the app has no Pages, no fallback rules and no header rules. For example, `/t/:id` rewritten to `/app.html` in `public/`. A rewrite dispatches its destination back into the generated app. In that setup the app has no not-found handler, so nothing asks `ASSETS` for `/app.html`, and Hono answers 404. This change also adds the not-found handler when there is a rewrite (a redirect rule with status 200). Apps with only 3xx redirects are not affected. A new test in `compile.test.ts` fails on `main` and passes with this change. Co-authored-by: meganemura <290611+meganemura@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
1 parent 855bdf2 commit a9f607f

2 files changed

Lines changed: 9 additions & 1 deletion

File tree

‎packages/void/src/router/compile.ts‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,9 @@ export function compileRouteTable(
414414
);
415415
} else if (
416416
emitEdgeRules &&
417-
(options.fallbackRules?.length || (!options.nodeTarget && options.headerRules?.length)) &&
417+
(options.fallbackRules?.length ||
418+
options.redirectRules?.some((rule) => rule.status === 200) ||
419+
(!options.nodeTarget && options.headerRules?.length)) &&
418420
!(pages && scan.pages.pages.length > 0)
419421
) {
420422
lines.push(

‎packages/void/test/unit/compile.test.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1394,6 +1394,12 @@ describe('typed runtime metadata wiring', () => {
13941394
expect(managed).not.toContain('const __routingRules');
13951395
expect(managed).not.toContain('app.notFound');
13961396
});
1397+
it('looks rewrite destinations up in static assets', () => {
1398+
const rewrite = [{ source: '/', destination: '/index.html', status: 200, force: true }];
1399+
expect(compile({ dev: false, redirectRules: rewrite })).toContain(
1400+
'app.notFound(__createAssetNotFound',
1401+
);
1402+
});
13971403
it('wires fetch validation, opaque internal routes and optional ISR through runtime callbacks', () => {
13981404
const code = compileWorkerEntry({
13991405
envSchemaModule: { importPath: '/env.ts', helperPath: '/env-helpers.ts' },

0 commit comments

Comments
 (0)