mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 06:05:11 +00:00
feat(config): serverMiddleware
as a simple key/value object (#6414)
This commit is contained in:
parent
92c7f4ed24
commit
bdcc7dd341
@ -410,5 +410,10 @@ export function getNuxtConfig (_options) {
|
||||
options.server.timing = { total: true, ...timing }
|
||||
}
|
||||
|
||||
if (isPureObject(options.serverMiddleware)) {
|
||||
options.serverMiddleware = Object.entries(options.serverMiddleware)
|
||||
.map(([ path, handler ]) => ({ path, handler }))
|
||||
}
|
||||
|
||||
return options
|
||||
}
|
||||
|
@ -266,6 +266,18 @@ describe('config: options', () => {
|
||||
})
|
||||
})
|
||||
|
||||
describe('config: serverMiddleware', () => {
|
||||
test('should transform serverMiddleware hash', () => {
|
||||
const serverMiddleware = {
|
||||
'/resource': (req, res, next) => {
|
||||
}
|
||||
}
|
||||
const config = getNuxtConfig({ serverMiddleware })
|
||||
expect(config.serverMiddleware[0].path).toBe('/resource')
|
||||
expect(config.serverMiddleware[0].handler).toBe(serverMiddleware['/resource'])
|
||||
})
|
||||
})
|
||||
|
||||
describe('config: router', () => {
|
||||
test('should sanitize router.base', () => {
|
||||
const config = getNuxtConfig({ router: { base: '/foo' } })
|
||||
|
Loading…
Reference in New Issue
Block a user