Skip to content

Commit 97d8172

Browse files
committed
refactor(analyze): use srvx to serve analysis results
1 parent 2b40c32 commit 97d8172

File tree

1 file changed

+23
-25
lines changed

1 file changed

+23
-25
lines changed

packages/nuxi/src/commands/analyze.ts

Lines changed: 23 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,16 +6,34 @@ import process from 'node:process'
66
import { defineCommand } from 'citty'
77
import { defu } from 'defu'
88
import { H3, lazyEventHandler } from 'h3-next'
9-
import { listen } from 'listhen'
109
import { join, resolve } from 'pathe'
11-
import { toNodeHandler } from 'srvx/node'
10+
import { serve } from 'srvx'
1211

1312
import { overrideEnv } from '../utils/env'
1413
import { clearDir } from '../utils/fs'
1514
import { loadKit } from '../utils/kit'
1615
import { logger } from '../utils/logger'
1716
import { cwdArgs, dotEnvArgs, extendsArgs, legacyRootDirArgs, logLevelArgs } from './_shared'
1817

18+
const indexHtml = `
19+
<!DOCTYPE html>
20+
<html lang="en">
21+
<head>
22+
<meta charset="utf-8">
23+
<title>Nuxt Bundle Stats (experimental)</title>
24+
</head>
25+
<h1>Nuxt Bundle Stats (experimental)</h1>
26+
<ul>
27+
<li>
28+
<a href="/nitro">Nitro server bundle stats</a>
29+
</li>
30+
<li>
31+
<a href="/client">Client bundle stats</a>
32+
</li>
33+
</ul>
34+
</html>
35+
`.trim()
36+
1937
export default defineCommand({
2038
meta: {
2139
name: 'analyze',
@@ -125,29 +143,9 @@ export default defineCommand({
125143

126144
app.use('/client', serveFile(join(analyzeDir, 'client.html')))
127145
app.use('/nitro', serveFile(join(analyzeDir, 'nitro.html')))
128-
app.use(() => new Response(
129-
`<!DOCTYPE html>
130-
<html lang="en">
131-
<head>
132-
<meta charset="utf-8">
133-
<title>Nuxt Bundle Stats (experimental)</title>
134-
</head>
135-
<h1>Nuxt Bundle Stats (experimental)</h1>
136-
<ul>
137-
<li>
138-
<a href="/nitro">Nitro server bundle stats</a>
139-
</li>
140-
<li>
141-
<a href="/client">Client bundle stats</a>
142-
</li>
143-
</ul>
144-
</html>
145-
`,
146-
opts,
147-
),
148-
)
149-
150-
await listen(toNodeHandler(app.fetch))
146+
app.use(() => new Response(indexHtml, opts))
147+
148+
await serve(app).serve()
151149
}
152150
},
153151
})

0 commit comments

Comments
 (0)