feat(config): serverMiddleware as a simple key/value object (#6414)

This commit is contained in:
Jonas Galvez 2019-09-29 06:11:25 -03:00 committed by Pooya Parsa
parent 92c7f4ed24
commit bdcc7dd341
2 changed files with 17 additions and 0 deletions

View File

@ -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
}

View File

@ -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' } })