fix(server): HMR for sub-app serverMiddleware without path (#7146)

This commit is contained in:
Pooya Parsa 2020-03-27 22:30:43 +01:00 committed by GitHub
parent 06073697f4
commit 318aad2aed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View File

@ -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()

View File

@ -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
}
// Return updated item
return serverStackItem

View File

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