Skip to content

Commit

Permalink
feat(config): serverMiddleware as a simple key/value object (#6414)
Browse files Browse the repository at this point in the history
  • Loading branch information
galvez authored and pi0 committed Sep 29, 2019
1 parent 92c7f4e commit bdcc7dd
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/config/src/options.js
Expand Up @@ -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
}
12 changes: 12 additions & 0 deletions packages/config/test/options.test.js
Expand Up @@ -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' } })
Expand Down

0 comments on commit bdcc7dd

Please sign in to comment.