diff --git a/packages/config/src/options.js b/packages/config/src/options.js index aa2341727d..243f673ebc 100644 --- a/packages/config/src/options.js +++ b/packages/config/src/options.js @@ -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 } diff --git a/packages/config/test/options.test.js b/packages/config/test/options.test.js index 0f58aceb02..87166c45c9 100644 --- a/packages/config/test/options.test.js +++ b/packages/config/test/options.test.js @@ -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' } })