mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-27 08:02:01 +00:00
chore: serverMiddleware HMR improvements (#6896)
* chore(server): fallback route for resolveMiddleware * chore(server): support express HMR [release]
This commit is contained in:
parent
a375a6c305
commit
a84f31d2a9
@ -206,6 +206,12 @@ export default class Server {
|
||||
}
|
||||
}
|
||||
|
||||
// SubApp (Express)
|
||||
if (typeof middleware.handle.handle === 'function') {
|
||||
const server = middleware.handle
|
||||
middleware.handle = server.handle.bind(server)
|
||||
}
|
||||
|
||||
return middleware
|
||||
}
|
||||
|
||||
@ -222,10 +228,7 @@ export default class Server {
|
||||
consola.error('ServerMiddleware Error:', error)
|
||||
|
||||
// Placeholder for error
|
||||
middleware = {
|
||||
route: '#error',
|
||||
handle: (req, res, next) => { next(error) }
|
||||
}
|
||||
middleware = (req, res, next) => { next(error) }
|
||||
}
|
||||
|
||||
// Normalize
|
||||
@ -237,10 +240,15 @@ export default class Server {
|
||||
return middleware
|
||||
}
|
||||
|
||||
resolveMiddleware (middleware) {
|
||||
resolveMiddleware (middleware, fallbackRoute = '/') {
|
||||
// Ensure middleware is normalized
|
||||
middleware = this._normalizeMiddleware(middleware)
|
||||
|
||||
// Fallback route
|
||||
if (!middleware.route) {
|
||||
middleware.route = fallbackRoute
|
||||
}
|
||||
|
||||
// Resolve final route
|
||||
middleware.route = (
|
||||
(middleware.prefix !== false ? this.options.router.base : '') +
|
||||
@ -255,7 +263,7 @@ export default class Server {
|
||||
|
||||
useMiddleware (middleware) {
|
||||
const { route, handle } = this.resolveMiddleware(middleware)
|
||||
this.app.use(route.includes('#error') ? '/' : route, handle)
|
||||
this.app.use(route, handle)
|
||||
}
|
||||
|
||||
replaceMiddleware (query, middleware) {
|
||||
@ -275,7 +283,7 @@ export default class Server {
|
||||
}
|
||||
|
||||
// Resolve middleware
|
||||
const { route, handle } = this.resolveMiddleware(middleware)
|
||||
const { route, handle } = this.resolveMiddleware(middleware, serverStackItem.route)
|
||||
|
||||
// Update serverStackItem
|
||||
serverStackItem.handle = handle
|
||||
|
Loading…
Reference in New Issue
Block a user