diff --git a/packages/builder/src/builder.js b/packages/builder/src/builder.js index 6b4c90fb00..b40b6f93f9 100644 --- a/packages/builder/src/builder.js +++ b/packages/builder/src/builder.js @@ -742,7 +742,7 @@ export default class Builder { } // Log - consola.info(`[HMR] ${chalk.cyan(newItem.route)} (${chalk.grey(fileName)})`) + consola.info(`[HMR] ${chalk.cyan(newItem.route || '/')} (${chalk.grey(fileName)})`) } // Tree may be changed so recreate watcher this.serverMiddlewareHMR() diff --git a/packages/server/src/server.js b/packages/server/src/server.js index 06afdccfb4..cd5cebfc3a 100644 --- a/packages/server/src/server.js +++ b/packages/server/src/server.js @@ -260,6 +260,11 @@ export default class Server { (typeof middleware.route === 'string' ? middleware.route : '') ).replace(/\/\//g, '/') + // Strip trailing slash + if (middleware.route.endsWith('/')) { + middleware.route = middleware.route.slice(0, -1) + } + // Assign _middleware to handle to make accessable from app.stack middleware.handle._middleware = middleware @@ -294,11 +299,7 @@ export default class Server { serverStackItem.handle = handle // Error State - if (route.includes('#error')) { - serverStackItem.route = serverStackItem.route || '/' - } else { - serverStackItem.route = route - } + serverStackItem.route = route // Return updated item return serverStackItem diff --git a/packages/server/test/server.test.js b/packages/server/test/server.test.js index 18f10ae1c7..798e23f20d 100644 --- a/packages/server/test/server.test.js +++ b/packages/server/test/server.test.js @@ -333,7 +333,7 @@ describe('server: server', () => { test('should use object middleware', () => { const nuxt = createNuxt() - nuxt.options.router = { base: '/' } + nuxt.options.router = { base: '' } const server = new Server(nuxt) const handler = jest.fn() @@ -348,7 +348,7 @@ describe('server: server', () => { test('should use function module middleware', () => { const nuxt = createNuxt() - nuxt.options.router = { base: '/' } + nuxt.options.router = { base: '' } const server = new Server(nuxt) const handler = jest.fn() nuxt.resolver.requireModule.mockReturnValueOnce(handler)