fix(nitro): filter alias in /_vfs listing (#1296)

This commit is contained in:
Anthony Fu 2021-10-21 01:30:42 +08:00 committed by GitHub
parent 9da9240ca8
commit 92547d8547
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,10 +4,11 @@ import { NitroContext } from '..'
export function handleVfs (ctx: NitroContext): Handle { export function handleVfs (ctx: NitroContext): Handle {
return (req) => { return (req) => {
if (req.url === '/') { if (req.url === '/') {
return '<!doctype html><html><body><ul>' + Object.keys(ctx.vfs).map((key) => { const items = Object.keys(ctx.vfs)
const url = encodeURIComponent(key) .filter(i => !i.startsWith('#'))
return `<li><a href="/_vfs/${url}">${key.replace(ctx._nuxt.rootDir, '')}</a></li>` .map(key => `<li><a href="/_vfs/${encodeURIComponent(key)}">${key.replace(ctx._nuxt.rootDir, '')}</a></li>`)
}).join('\n') + '</ul></body></html>' .join('\n')
return `<!doctype html><html><body><ul>${items}</ul></body></html>`
} }
const param = decodeURIComponent(req.url.slice(1)) const param = decodeURIComponent(req.url.slice(1))
if (param in ctx.vfs) { if (param in ctx.vfs) {