mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-30 01:17:16 +00:00
fix(bridge): normalize strings in vite middleware template (#2319)
This commit is contained in:
parent
0d85c9ef77
commit
3e82f0f2cb
@ -14,10 +14,16 @@ export const middlewareTemplate = {
|
||||
src: '',
|
||||
getContents (ctx: TemplateContext) {
|
||||
const { dir, router: { middleware }, srcDir } = ctx.nuxt.options
|
||||
const _middleware = ((typeof middleware !== 'undefined' && middleware) || []).map(m => ({
|
||||
filePath: resolve(srcDir, dir.middleware, m.src),
|
||||
id: m.name || m.src.replace(/[\\/]/g, '/').replace(/\.(js|ts)$/, '')
|
||||
}))
|
||||
const _middleware = ((typeof middleware !== 'undefined' && middleware) || []).map((m) => {
|
||||
// Normalize string middleware
|
||||
if (typeof m === 'string') {
|
||||
m = { src: m }
|
||||
}
|
||||
return {
|
||||
filePath: resolve(srcDir, dir.middleware, m.src),
|
||||
id: m.name || m.src.replace(/[\\/]/g, '/').replace(/\.(js|ts)$/, '')
|
||||
}
|
||||
})
|
||||
return `${_middleware.map(m => `import $${hash(m.id)} from '${m.filePath}'`).join('\n')}
|
||||
const middleware = {
|
||||
${_middleware.map(m => ` ['${m.id}']: $${hash(m.id)}`).join(',\n')}
|
||||
|
Loading…
Reference in New Issue
Block a user