mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-23 14:15:13 +00:00
fix(server): HMR for sub-app serverMiddleware without path (#7146)
This commit is contained in:
parent
06073697f4
commit
318aad2aed
@ -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()
|
||||
|
@ -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
|
||||
|
@ -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)
|
||||
|
Loading…
Reference in New Issue
Block a user