Skip to content

Commit

Permalink
feat(prerender)!: write html files to subfolder (resolves #166)
Browse files Browse the repository at this point in the history
  • Loading branch information
pi0 committed May 4, 2022
1 parent e1c234e commit cdcd35a
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/prerender.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion test/fixture/api/hello.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export default () => 'Hello API'
export default () => ({ message: 'Hello API' })
2 changes: 1 addition & 1 deletion test/tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down

0 comments on commit cdcd35a

Please sign in to comment.