mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-26 15:42:09 +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: '',
|
src: '',
|
||||||
getContents (ctx: TemplateContext) {
|
getContents (ctx: TemplateContext) {
|
||||||
const { dir, router: { middleware }, srcDir } = ctx.nuxt.options
|
const { dir, router: { middleware }, srcDir } = ctx.nuxt.options
|
||||||
const _middleware = ((typeof middleware !== 'undefined' && middleware) || []).map(m => ({
|
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),
|
filePath: resolve(srcDir, dir.middleware, m.src),
|
||||||
id: m.name || m.src.replace(/[\\/]/g, '/').replace(/\.(js|ts)$/, '')
|
id: m.name || m.src.replace(/[\\/]/g, '/').replace(/\.(js|ts)$/, '')
|
||||||
}))
|
}
|
||||||
|
})
|
||||||
return `${_middleware.map(m => `import $${hash(m.id)} from '${m.filePath}'`).join('\n')}
|
return `${_middleware.map(m => `import $${hash(m.id)} from '${m.filePath}'`).join('\n')}
|
||||||
const middleware = {
|
const middleware = {
|
||||||
${_middleware.map(m => ` ['${m.id}']: $${hash(m.id)}`).join(',\n')}
|
${_middleware.map(m => ` ['${m.id}']: $${hash(m.id)}`).join(',\n')}
|
||||||
|
Loading…
Reference in New Issue
Block a user