mirror of
https://github.com/nuxt/nuxt.git
synced 2025-01-31 07:40:33 +00:00
improve useMiddleware
This commit is contained in:
parent
a71ac0f41a
commit
f933dd1f32
@ -171,16 +171,25 @@ export default class Renderer extends Tapable {
|
||||
|
||||
useMiddleware (m) {
|
||||
// Resolve
|
||||
const $m = m
|
||||
let src
|
||||
if (typeof m === 'string') {
|
||||
m = require(this.nuxt.resolvePath(m))
|
||||
src = this.nuxt.resolvePath(m)
|
||||
m = require(src)
|
||||
}
|
||||
// Handler
|
||||
if (m && typeof m.handler === 'string') {
|
||||
m.handler = require(this.nuxt.resolvePath(m.handler))
|
||||
if (typeof m.handler === 'string') {
|
||||
src = this.nuxt.resolvePath(m.handler)
|
||||
m.handler = require(src)
|
||||
}
|
||||
// Use middleware
|
||||
|
||||
const handler = m.handler || m
|
||||
const path = (this.options.router.base + (m.path ? m.path : '')).replace(/\/\//g, '/')
|
||||
|
||||
// Inject $src and $m to final handler
|
||||
if (src) handler.$src = src
|
||||
handler.$m = $m
|
||||
|
||||
// Use middleware
|
||||
this.app.use(path, handler)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user