fix(nitro): omit /index from generated api urls (#1371)

This commit is contained in:
Francisco Buceta 2021-10-22 19:04:02 +02:00 committed by GitHub
parent d5f2de7c43
commit 54549cfc61
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 12 additions and 3 deletions

View File

@ -24,7 +24,12 @@ export interface ServerMiddleware {
function filesToMiddleware (files: string[], baseDir: string, basePath: string, overrides?: Partial<ServerMiddleware>): ServerMiddleware[] {
return files.map((file) => {
const route = joinURL(basePath, file.substr(0, file.length - extname(file).length))
const route = joinURL(
basePath,
file
.substr(0, file.length - extname(file).length)
.replace(/\/index$/, '')
)
const handle = resolve(baseDir, file)
return {
route,

View File

@ -0,0 +1 @@
export default () => 'Hey API'

View File

@ -0,0 +1 @@
export default () => 'Hey API'

View File

@ -66,7 +66,9 @@ export function testNitroBehavior(_ctx, getHandler) {
})
it('API Works', async () => {
const { data } = await handler({ url: '/api/hello' })
expect(destr(data)).to.have.string('Hello API')
const { data: helloData } = await handler({ url: '/api/hello' })
const { data: heyData } = await handler({ url: '/api/hey' })
expect(destr(helloData)).to.have.string('Hello API')
expect(destr(heyData)).to.have.string('Hey API')
})
}