Skip to content

Commit cd99176

Browse files
committed
Fix Node 26 trailing-slash asset probes.
1 parent 5966af4 commit cd99176

2 files changed

Lines changed: 65 additions & 38 deletions

File tree

‎packages/void/src/runtime/routing-pages.ts‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,16 @@ export function createPagesFallback(options: {
177177
) {
178178
const url = new URL(c.req.url);
179179
url.pathname += '/';
180-
const index = await assets.fetch(new Request(url, c.req.raw));
180+
// Node adapters can expose Request wrappers whose native getters cannot
181+
// be read as RequestInit. Copy only what this GET/HEAD probe needs.
182+
const index = await assets.fetch(
183+
new Request(url, {
184+
method: c.req.method,
185+
headers: c.req.raw.headers,
186+
redirect: c.req.raw.redirect,
187+
signal: c.req.raw.signal,
188+
}),
189+
);
181190
directoryIndex = index.status === 200;
182191
await index.body?.cancel();
183192
}

‎packages/void/test/integration/trailing-slash.test.ts‎

Lines changed: 55 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -109,45 +109,63 @@ export const action = (c) => c.json({ value: c.req.param(${JSON.stringify(name)}
109109
'about-title',
110110
);
111111
});
112-
it('redirects to the page URL in dev and production and leaves API routes alone', async () => {
113-
for (const { base, mode } of servers) {
114-
const redirect = await fetch(`${base}/about?test=1`, { redirect: 'manual' });
115-
expect([301, 307, 308], mode).toContain(redirect.status);
116-
expect(new URL(redirect.headers.get('location')!, base).href, mode).toBe(
117-
`${base}/about/?test=1`,
118-
);
119-
await redirect.text();
120-
const page = await fetch(`${base}/about/`);
121-
expect(page.status).toBe(200);
122-
expect(await page.text()).toContain('about-title');
123-
for (const [path, value] of [
124-
['posts/hello', 'hello'],
125-
['files/guides/intro', 'guides/intro'],
126-
]) {
127-
const dynamicRedirect = await fetch(`${base}/${path}`, { redirect: 'manual' });
128-
expect([301, 307, 308], `${mode}: ${path}`).toContain(dynamicRedirect.status);
129-
await dynamicRedirect.text();
130-
const dynamicPage = await fetch(`${base}/${path}/`);
131-
expect(dynamicPage.status, `${mode}: ${path}`).toBe(200);
132-
expect(await dynamicPage.text()).toContain(`<h1>${value}</h1>`);
112+
it.each(['GET', 'HEAD'])(
113+
'redirects %s to the page URL and leaves API routes alone',
114+
async (method) => {
115+
for (const { base, mode } of servers) {
116+
const redirect = await fetch(`${base}/about?test=1`, { method, redirect: 'manual' });
117+
expect([301, 307, 308], mode).toContain(redirect.status);
118+
expect(new URL(redirect.headers.get('location')!, base).href, mode).toBe(
119+
`${base}/about/?test=1`,
120+
);
121+
await redirect.text();
122+
const page = await fetch(`${base}/about/`, { method });
123+
expect(page.status).toBe(200);
124+
const html = await page.text();
125+
if (method === 'HEAD') {
126+
expect(html).toBe('');
127+
} else {
128+
expect(html).toContain('about-title');
129+
}
130+
for (const [path, value] of [
131+
['posts/hello', 'hello'],
132+
['files/guides/intro', 'guides/intro'],
133+
]) {
134+
const dynamicRedirect = await fetch(`${base}/${path}`, { method, redirect: 'manual' });
135+
expect([301, 307, 308], `${mode}: ${path}`).toContain(dynamicRedirect.status);
136+
await dynamicRedirect.text();
137+
const dynamicPage = await fetch(`${base}/${path}/`, { method });
138+
expect(dynamicPage.status, `${mode}: ${path}`).toBe(200);
139+
const html = await dynamicPage.text();
140+
if (method === 'HEAD') {
141+
expect(html).toBe('');
142+
} else {
143+
expect(html).toContain(`<h1>${value}</h1>`);
144+
}
145+
}
146+
const api = await fetch(`${base}/api/hello`, { method, redirect: 'manual' });
147+
expect(api.status).toBe(200);
148+
await api.text();
133149
}
134-
const api = await fetch(`${base}/api/hello`, { redirect: 'manual' });
135-
expect(api.status).toBe(200);
136-
await api.text();
137-
}
138-
});
139-
it('keeps public files accessible beside a catch-all page', async () => {
140-
for (const { base, mode } of servers) {
141-
for (const file of ['asset.js', 'favicon.ico', 'LICENSE']) {
142-
const response = await fetch(`${base}/${file}`, { redirect: 'manual' });
143-
expect(response.status, `${mode}: ${file}`).toBe(200);
144-
expect(await response.text(), `${mode}: ${file}`).toBe('public file');
150+
},
151+
);
152+
it.each(['GET', 'HEAD'])(
153+
'keeps public files accessible to %s beside a catch-all page',
154+
async (method) => {
155+
for (const { base, mode } of servers) {
156+
for (const file of ['asset.js', 'favicon.ico', 'LICENSE']) {
157+
const response = await fetch(`${base}/${file}`, { method, redirect: 'manual' });
158+
expect(response.status, `${mode}: ${file}`).toBe(200);
159+
expect(await response.text(), `${mode}: ${file}`).toBe(
160+
method === 'HEAD' ? '' : 'public file',
161+
);
162+
}
163+
const html = await fetch(`${base}/terms.html`, { method });
164+
expect(html.status, mode).toBe(200);
165+
expect(await html.text(), mode).toBe(method === 'HEAD' ? '' : 'public file');
145166
}
146-
const html = await fetch(`${base}/terms.html`);
147-
expect(html.status, mode).toBe(200);
148-
expect(await html.text(), mode).toBe('public file');
149-
}
150-
});
167+
},
168+
);
151169
it('preserves catch-all parameters in actions and supports empty anonymous catch-alls', async () => {
152170
for (const { base, mode } of servers) {
153171
const action = await fetch(`${base}/files/guides/intro/`, {

0 commit comments

Comments
 (0)