mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +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
|
// 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
|
// Tree may be changed so recreate watcher
|
||||||
this.serverMiddlewareHMR()
|
this.serverMiddlewareHMR()
|
||||||
|
@ -260,6 +260,11 @@ export default class Server {
|
|||||||
(typeof middleware.route === 'string' ? middleware.route : '')
|
(typeof middleware.route === 'string' ? middleware.route : '')
|
||||||
).replace(/\/\//g, '/')
|
).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
|
// Assign _middleware to handle to make accessable from app.stack
|
||||||
middleware.handle._middleware = middleware
|
middleware.handle._middleware = middleware
|
||||||
|
|
||||||
@ -294,11 +299,7 @@ export default class Server {
|
|||||||
serverStackItem.handle = handle
|
serverStackItem.handle = handle
|
||||||
|
|
||||||
// Error State
|
// Error State
|
||||||
if (route.includes('#error')) {
|
serverStackItem.route = route
|
||||||
serverStackItem.route = serverStackItem.route || '/'
|
|
||||||
} else {
|
|
||||||
serverStackItem.route = route
|
|
||||||
}
|
|
||||||
|
|
||||||
// Return updated item
|
// Return updated item
|
||||||
return serverStackItem
|
return serverStackItem
|
||||||
|
@ -333,7 +333,7 @@ describe('server: server', () => {
|
|||||||
|
|
||||||
test('should use object middleware', () => {
|
test('should use object middleware', () => {
|
||||||
const nuxt = createNuxt()
|
const nuxt = createNuxt()
|
||||||
nuxt.options.router = { base: '/' }
|
nuxt.options.router = { base: '' }
|
||||||
const server = new Server(nuxt)
|
const server = new Server(nuxt)
|
||||||
const handler = jest.fn()
|
const handler = jest.fn()
|
||||||
|
|
||||||
@ -348,7 +348,7 @@ describe('server: server', () => {
|
|||||||
|
|
||||||
test('should use function module middleware', () => {
|
test('should use function module middleware', () => {
|
||||||
const nuxt = createNuxt()
|
const nuxt = createNuxt()
|
||||||
nuxt.options.router = { base: '/' }
|
nuxt.options.router = { base: '' }
|
||||||
const server = new Server(nuxt)
|
const server = new Server(nuxt)
|
||||||
const handler = jest.fn()
|
const handler = jest.fn()
|
||||||
nuxt.resolver.requireModule.mockReturnValueOnce(handler)
|
nuxt.resolver.requireModule.mockReturnValueOnce(handler)
|
||||||
|
Loading…
Reference in New Issue
Block a user