mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-14 01:53:55 +00:00
fix(nitro): omit /index
from generated api urls (#1371)
This commit is contained in:
parent
d5f2de7c43
commit
54549cfc61
@ -24,7 +24,12 @@ export interface ServerMiddleware {
|
|||||||
|
|
||||||
function filesToMiddleware (files: string[], baseDir: string, basePath: string, overrides?: Partial<ServerMiddleware>): ServerMiddleware[] {
|
function filesToMiddleware (files: string[], baseDir: string, basePath: string, overrides?: Partial<ServerMiddleware>): ServerMiddleware[] {
|
||||||
return files.map((file) => {
|
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)
|
const handle = resolve(baseDir, file)
|
||||||
return {
|
return {
|
||||||
route,
|
route,
|
||||||
|
1
test/fixtures/basic/server/api/hey/index.ts
vendored
Normal file
1
test/fixtures/basic/server/api/hey/index.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export default () => 'Hey API'
|
1
test/fixtures/bridge/server/api/hey/index.ts
vendored
Normal file
1
test/fixtures/bridge/server/api/hey/index.ts
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
export default () => 'Hey API'
|
@ -66,7 +66,9 @@ export function testNitroBehavior(_ctx, getHandler) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
it('API Works', async () => {
|
it('API Works', async () => {
|
||||||
const { data } = await handler({ url: '/api/hello' })
|
const { data: helloData } = await handler({ url: '/api/hello' })
|
||||||
expect(destr(data)).to.have.string('Hello API')
|
const { data: heyData } = await handler({ url: '/api/hey' })
|
||||||
|
expect(destr(helloData)).to.have.string('Hello API')
|
||||||
|
expect(destr(heyData)).to.have.string('Hey API')
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user