diff --git a/src/prerender.ts b/src/prerender.ts index fc4a3ed91a..d2b1a35894 100644 --- a/src/prerender.ts +++ b/src/prerender.ts @@ -47,9 +47,10 @@ export async function prerender (nitro: Nitro) { if (res.status !== 200) { throw new Error(`[${res.status}] ${res.statusText}`) } + + const isImplicitHTML = !route.endsWith('.html') && (res.headers.get('content-type') || '').includes('html') const routeWithIndex = route.endsWith('/') ? route + 'index' : route - const isImplicitHTML = (res.headers.get('content-type') || '').includes('html') - const fileName = isImplicitHTML ? routeWithIndex + '.html' : routeWithIndex + const fileName = isImplicitHTML ? route + '/index.html' : routeWithIndex const filePath = join(nitro.options.output.publicDir, fileName) await writeFile(filePath, contents) // Crawl Links diff --git a/test/fixture/api/hello.ts b/test/fixture/api/hello.ts index 2d81ce2188..22c4854507 100644 --- a/test/fixture/api/hello.ts +++ b/test/fixture/api/hello.ts @@ -1 +1 @@ -export default () => 'Hello API' +export default () => ({ message: 'Hello API' }) diff --git a/test/tests.ts b/test/tests.ts index 1218f819c6..c48ec47511 100644 --- a/test/tests.ts +++ b/test/tests.ts @@ -81,7 +81,7 @@ export function testNitro (ctx: Context, getHandler: () => TestHandler | Promise it('API Works', async () => { const { data: helloData } = await callHandler({ url: '/api/hello' }) - expect(helloData).to.have.string('Hello API') + expect(helloData).to.toMatchObject({ message: 'Hello API' }) const { data: heyData } = await callHandler({ url: '/api/hey' }) expect(heyData).to.have.string('Hey API')