From bdcc7dd341c407f4dc96657397429c2491af0fdd Mon Sep 17 00:00:00 2001 From: Jonas Galvez Date: Sun, 29 Sep 2019 06:11:25 -0300 Subject: [PATCH] feat(config): `serverMiddleware` as a simple key/value object (#6414) --- packages/config/src/options.js | 5 +++++ packages/config/test/options.test.js | 12 ++++++++++++ 2 files changed, 17 insertions(+) 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' } })