import { createError, Handle } from 'h3' import { NitroContext } from '..' export function handleVfs (ctx: NitroContext): Handle { return (req) => { if (req.url === '/') { const items = Object.keys(ctx.vfs) .filter(i => !i.startsWith('#')) .map(key => `
  • ${key.replace(ctx._nuxt.rootDir, '')}
  • `) .join('\n') return `` } const param = decodeURIComponent(req.url.slice(1)) if (param in ctx.vfs) { return editorTemplate({ readOnly: true, language: param.endsWith('html') ? 'html' : 'javascript', theme: 'vs-dark', value: ctx.vfs[param] }) } return createError({ message: 'File not found', statusCode: 404 }) } } const monacoVersion = '0.20.0' const monacoUrl = `https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/${monacoVersion}/min` const vsUrl = `${monacoUrl}/vs` const editorTemplate = (options: Record) => `
    `