nitro-nightly 4.0.0-20251030-091344-d4418b98 → 4.0.0-20251030-122334-09c1a7a8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/_build/common.mjs +763 -0
- package/dist/_build/rolldown.mjs +216 -0
- package/dist/_build/rollup.mjs +359 -0
- package/dist/_build/vite.build.mjs +67 -0
- package/dist/_build/vite.plugin.mjs +762 -0
- package/dist/_chunks/B-7HiF0V.mjs +1303 -0
- package/dist/_chunks/B3asVbT4.mjs +151 -0
- package/dist/_chunks/B5ooyfLk.mjs +372 -0
- package/dist/_chunks/DXMHy5ca.mjs +43 -0
- package/dist/_dev.d.mts +12 -0
- package/dist/_dev.mjs +675 -0
- package/dist/_libs/acorn.mjs +5034 -0
- package/dist/_libs/c12.mjs +2798 -0
- package/dist/_libs/chokidar.mjs +1560 -0
- package/dist/_libs/citty.mjs +333 -0
- package/dist/_libs/commondir.mjs +22 -0
- package/dist/_libs/compatx.mjs +46 -0
- package/dist/_libs/confbox.mjs +2920 -0
- package/dist/_libs/debug.mjs +848 -0
- package/dist/_libs/deepmerge.mjs +86 -0
- package/dist/_libs/depd.mjs +314 -0
- package/dist/_libs/dot-prop.mjs +138 -0
- package/dist/_libs/duplexer.mjs +71 -0
- package/dist/_libs/ee-first.mjs +68 -0
- package/dist/_libs/encodeurl.mjs +49 -0
- package/dist/_libs/escape-html.mjs +58 -0
- package/dist/_libs/escape-string-regexp.mjs +8 -0
- package/dist/_libs/estree-walker.mjs +330 -0
- package/dist/_libs/etag.mjs +75 -0
- package/dist/{_chunks/_deps → _libs}/fdir.mjs +49 -104
- package/dist/_libs/fresh.mjs +85 -0
- package/dist/_libs/function-bind.mjs +63 -0
- package/dist/_libs/gen-mapping.mjs +612 -0
- package/dist/_libs/giget.mjs +19076 -0
- package/dist/_libs/gzip-size.mjs +21 -0
- package/dist/_libs/hasown.mjs +14 -0
- package/dist/_libs/http-errors.mjs +436 -0
- package/dist/_libs/httpxy.mjs +410 -0
- package/dist/_libs/is-core-module.mjs +220 -0
- package/dist/_libs/is-module.mjs +13 -0
- package/dist/_libs/is-reference.mjs +32 -0
- package/dist/{_chunks/_deps → _libs}/js-tokens.mjs +83 -112
- package/dist/_libs/klona.mjs +90 -0
- package/dist/_libs/knitwork.mjs +124 -0
- package/dist/_libs/local-pkg.mjs +1686 -0
- package/dist/{_chunks/_deps → _libs}/magic-string.mjs +272 -629
- package/dist/_libs/mime-db.mjs +7642 -0
- package/dist/_libs/mime-types.mjs +162 -0
- package/dist/_libs/mime.mjs +1391 -0
- package/dist/_libs/node-fetch-native.mjs +173 -0
- package/dist/_libs/on-finished.mjs +170 -0
- package/dist/_libs/parseurl.mjs +103 -0
- package/dist/_libs/path-parse.mjs +47 -0
- package/dist/_libs/pathe.mjs +41 -0
- package/dist/_libs/picomatch.mjs +1673 -0
- package/dist/_libs/plugin-alias.mjs +64 -0
- package/dist/_libs/plugin-commonjs.mjs +1489 -0
- package/dist/_libs/plugin-inject.mjs +135 -0
- package/dist/_libs/plugin-json.mjs +36 -0
- package/dist/_libs/plugin-node-resolve.mjs +1553 -0
- package/dist/_libs/plugin-replace.mjs +104 -0
- package/dist/_libs/pretty-bytes.mjs +116 -0
- package/dist/_libs/range-parser.mjs +102 -0
- package/dist/_libs/remapping.mjs +117 -0
- package/dist/{_chunks/_deps → _libs}/rou3.mjs +7 -22
- package/dist/_libs/send.mjs +857 -0
- package/dist/_libs/serve-static.mjs +124 -0
- package/dist/_libs/std-env.mjs +158 -0
- package/dist/_libs/strip-literal.mjs +51 -0
- package/dist/{_chunks/_deps → _libs}/tinyglobby.mjs +32 -33
- package/dist/_libs/ultrahtml.mjs +138 -0
- package/dist/_libs/unimport.mjs +3520 -0
- package/dist/_libs/untyped.mjs +271 -0
- package/dist/_libs/unwasm.mjs +5825 -0
- package/dist/{_chunks/_deps/@pi0 → _libs}/vite-plugin-fullstack.mjs +28 -42
- package/dist/_presets.mjs +1723 -0
- package/dist/builder.d.mts +37 -35
- package/dist/builder.mjs +45 -117
- package/dist/cli/_chunks/build.mjs +43 -0
- package/dist/cli/_chunks/common.mjs +15 -0
- package/dist/cli/_chunks/detect-acorn.mjs +12 -0
- package/dist/cli/_chunks/dev.mjs +79 -0
- package/dist/cli/_chunks/dist.mjs +3 -0
- package/dist/cli/_chunks/dist2.mjs +4 -0
- package/dist/cli/_chunks/esm.mjs +3 -0
- package/dist/cli/_chunks/json5.mjs +4 -0
- package/dist/cli/_chunks/jsonc.mjs +4 -0
- package/dist/cli/_chunks/list.mjs +27 -0
- package/dist/cli/_chunks/multipart-parser.mjs +6 -0
- package/dist/cli/_chunks/prepare.mjs +19 -0
- package/dist/cli/_chunks/run.mjs +55 -0
- package/dist/cli/_chunks/task.mjs +16 -0
- package/dist/cli/_chunks/toml.mjs +4 -0
- package/dist/cli/_chunks/yaml.mjs +4 -0
- package/dist/cli/index.d.mts +1 -1
- package/dist/cli/index.mjs +19 -18
- package/dist/presets/_nitro/runtime/nitro-dev.d.mts +1 -0
- package/dist/presets/_nitro/runtime/nitro-dev.mjs +42 -33
- package/dist/presets/_nitro/runtime/nitro-prerenderer.d.mts +2 -2
- package/dist/presets/_nitro/runtime/nitro-prerenderer.mjs +4 -8
- package/dist/presets/_nitro/runtime/service-worker.d.mts +1 -0
- package/dist/presets/_nitro/runtime/service-worker.mjs +14 -11
- package/dist/presets/aws-amplify/runtime/aws-amplify.d.mts +1 -0
- package/dist/presets/aws-amplify/runtime/aws-amplify.mjs +6 -5
- package/dist/presets/aws-lambda/runtime/_utils.d.mts +8 -13
- package/dist/presets/aws-lambda/runtime/_utils.mjs +95 -81
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.d.mts +1 -2
- package/dist/presets/aws-lambda/runtime/aws-lambda-streaming.mjs +25 -27
- package/dist/presets/aws-lambda/runtime/aws-lambda.mjs +7 -7
- package/dist/presets/azure/runtime/_utils.mjs +43 -43
- package/dist/presets/azure/runtime/azure-swa.d.mts +2 -2
- package/dist/presets/azure/runtime/azure-swa.mjs +22 -21
- package/dist/presets/bun/runtime/bun.d.mts +1 -0
- package/dist/presets/bun/runtime/bun.mjs +18 -17
- package/dist/presets/cloudflare/runtime/_module-handler.d.mts +10 -7
- package/dist/presets/cloudflare/runtime/_module-handler.mjs +78 -87
- package/dist/presets/cloudflare/runtime/cloudflare-durable.d.mts +6 -14
- package/dist/presets/cloudflare/runtime/cloudflare-durable.mjs +53 -58
- package/dist/presets/cloudflare/runtime/cloudflare-module.d.mts +1 -7
- package/dist/presets/cloudflare/runtime/cloudflare-module.mjs +12 -14
- package/dist/presets/cloudflare/runtime/cloudflare-pages.d.mts +12 -12
- package/dist/presets/cloudflare/runtime/cloudflare-pages.mjs +35 -39
- package/dist/presets/cloudflare/runtime/plugin.dev.d.mts +2 -2
- package/dist/presets/cloudflare/runtime/plugin.dev.mjs +86 -76
- package/dist/presets/deno/runtime/deno-deploy.d.mts +1 -0
- package/dist/presets/deno/runtime/deno-deploy.mjs +12 -11
- package/dist/presets/deno/runtime/deno-server.d.mts +2 -1
- package/dist/presets/deno/runtime/deno-server.mjs +31 -39
- package/dist/presets/netlify/runtime/netlify-edge.d.mts +2 -1
- package/dist/presets/netlify/runtime/netlify-edge.mjs +14 -11
- package/dist/presets/netlify/runtime/netlify.mjs +11 -17
- package/dist/presets/node/runtime/node-cluster.mjs +49 -48
- package/dist/presets/node/runtime/node-middleware.d.mts +3 -2
- package/dist/presets/node/runtime/node-middleware.mjs +7 -6
- package/dist/presets/node/runtime/node-server.mjs +33 -23
- package/dist/presets/standard/runtime/server.d.mts +1 -3
- package/dist/presets/standard/runtime/server.mjs +1 -3
- package/dist/presets/stormkit/runtime/stormkit.d.mts +13 -13
- package/dist/presets/stormkit/runtime/stormkit.mjs +20 -20
- package/dist/presets/vercel/runtime/vercel.d.mts +3 -3
- package/dist/presets/vercel/runtime/vercel.mjs +15 -14
- package/dist/presets/winterjs/runtime/winterjs.d.mts +2 -0
- package/dist/presets/winterjs/runtime/winterjs.mjs +72 -68
- package/dist/presets/zeabur/runtime/zeabur.d.mts +1 -1
- package/dist/runtime/index.d.mts +12 -1
- package/dist/runtime/index.mjs +12 -7
- package/dist/runtime/internal/app.mjs +175 -162
- package/dist/runtime/internal/cache.d.mts +10 -4
- package/dist/runtime/internal/cache.mjs +247 -216
- package/dist/runtime/internal/context.d.mts +9 -9
- package/dist/runtime/internal/context.mjs +17 -10
- package/dist/runtime/internal/database.mjs +8 -10
- package/dist/runtime/internal/error/dev.d.mts +5 -4
- package/dist/runtime/internal/error/dev.mjs +106 -105
- package/dist/runtime/internal/error/prod.d.mts +2 -2
- package/dist/runtime/internal/error/prod.mjs +48 -52
- package/dist/runtime/internal/error/utils.d.mts +4 -4
- package/dist/runtime/internal/error/utils.mjs +1 -1
- package/dist/runtime/internal/index.d.mts +2 -0
- package/dist/runtime/internal/index.mjs +2 -0
- package/dist/runtime/internal/lib/http-graceful-shutdown.d.mts +14 -14
- package/dist/runtime/internal/lib/http-graceful-shutdown.mjs +248 -209
- package/dist/runtime/internal/meta.d.mts +1 -1
- package/dist/runtime/internal/meta.mjs +1 -1
- package/dist/runtime/internal/plugin.d.mts +2 -2
- package/dist/runtime/internal/plugin.mjs +1 -1
- package/dist/runtime/internal/renderer.mjs +39 -31
- package/dist/runtime/internal/route-rules.d.mts +8 -8
- package/dist/runtime/internal/route-rules.mjs +53 -51
- package/dist/runtime/internal/routes/dev-tasks.d.mts +1 -30
- package/dist/runtime/internal/routes/dev-tasks.mjs +15 -17
- package/dist/runtime/internal/routes/openapi.d.mts +1 -0
- package/dist/runtime/internal/routes/openapi.mjs +81 -87
- package/dist/runtime/internal/routes/renderer-template.d.mts +1 -1
- package/dist/runtime/internal/routes/renderer-template.dev.d.mts +1 -2
- package/dist/runtime/internal/routes/renderer-template.dev.mjs +10 -17
- package/dist/runtime/internal/routes/renderer-template.mjs +1 -1
- package/dist/runtime/internal/routes/scalar.d.mts +1 -0
- package/dist/runtime/internal/routes/scalar.mjs +22 -23
- package/dist/runtime/internal/routes/swagger.d.mts +1 -0
- package/dist/runtime/internal/routes/swagger.mjs +9 -11
- package/dist/runtime/internal/runtime-config.d.mts +4 -4
- package/dist/runtime/internal/runtime-config.mjs +40 -35
- package/dist/runtime/internal/shutdown.d.mts +2 -7
- package/dist/runtime/internal/shutdown.mjs +30 -29
- package/dist/runtime/internal/static.mjs +63 -74
- package/dist/runtime/internal/storage.mjs +2 -2
- package/dist/runtime/internal/task.d.mts +6 -6
- package/dist/runtime/internal/task.mjs +56 -59
- package/dist/runtime/internal/utils.d.mts +1 -1
- package/dist/runtime/internal/utils.mjs +4 -10
- package/dist/types/index.d.mts +2566 -3851
- package/dist/types/index.mjs +1 -1
- package/dist/vite.d.mts +61 -51
- package/dist/vite.mjs +55 -132
- package/package.json +10 -10
- package/dist/_build/build.mjs +0 -368
- package/dist/_build/build2.mjs +0 -556
- package/dist/_build/info.mjs +0 -1002
- package/dist/_build/prepare.mjs +0 -1511
- package/dist/_build/snapshot.mjs +0 -185
- package/dist/_build/vite.mjs +0 -959
- package/dist/_build/vite2.mjs +0 -149
- package/dist/_chunks/_deps/@jridgewell/gen-mapping.mjs +0 -189
- package/dist/_chunks/_deps/@jridgewell/remapping.mjs +0 -137
- package/dist/_chunks/_deps/@jridgewell/resolve-uri.mjs +0 -231
- package/dist/_chunks/_deps/@jridgewell/sourcemap-codec.mjs +0 -173
- package/dist/_chunks/_deps/@jridgewell/trace-mapping.mjs +0 -170
- package/dist/_chunks/_deps/@rollup/plugin-alias.mjs +0 -89
- package/dist/_chunks/_deps/@rollup/plugin-commonjs.mjs +0 -2376
- package/dist/_chunks/_deps/@rollup/plugin-inject.mjs +0 -212
- package/dist/_chunks/_deps/@rollup/plugin-json.mjs +0 -37
- package/dist/_chunks/_deps/@rollup/plugin-node-resolve.mjs +0 -1386
- package/dist/_chunks/_deps/@rollup/plugin-replace.mjs +0 -133
- package/dist/_chunks/_deps/@rollup/pluginutils.mjs +0 -346
- package/dist/_chunks/_deps/acorn.mjs +0 -6225
- package/dist/_chunks/_deps/c12.mjs +0 -510
- package/dist/_chunks/_deps/chokidar.mjs +0 -1428
- package/dist/_chunks/_deps/citty.mjs +0 -460
- package/dist/_chunks/_deps/commondir.mjs +0 -77
- package/dist/_chunks/_deps/compatx.mjs +0 -76
- package/dist/_chunks/_deps/confbox.mjs +0 -300
- package/dist/_chunks/_deps/debug.mjs +0 -885
- package/dist/_chunks/_deps/deepmerge.mjs +0 -147
- package/dist/_chunks/_deps/depd.mjs +0 -550
- package/dist/_chunks/_deps/dot-prop.mjs +0 -282
- package/dist/_chunks/_deps/dotenv.mjs +0 -555
- package/dist/_chunks/_deps/duplexer.mjs +0 -1
- package/dist/_chunks/_deps/ee-first.mjs +0 -104
- package/dist/_chunks/_deps/encodeurl.mjs +0 -69
- package/dist/_chunks/_deps/escape-html.mjs +0 -87
- package/dist/_chunks/_deps/escape-string-regexp.mjs +0 -13
- package/dist/_chunks/_deps/estree-walker.mjs +0 -433
- package/dist/_chunks/_deps/etag.mjs +0 -147
- package/dist/_chunks/_deps/exsolve.mjs +0 -1416
- package/dist/_chunks/_deps/fresh.mjs +0 -145
- package/dist/_chunks/_deps/function-bind.mjs +0 -106
- package/dist/_chunks/_deps/giget.mjs +0 -451
- package/dist/_chunks/_deps/gzip-size.mjs +0 -19
- package/dist/_chunks/_deps/hasown.mjs +0 -19
- package/dist/_chunks/_deps/http-errors.mjs +0 -307
- package/dist/_chunks/_deps/httpxy.mjs +0 -580
- package/dist/_chunks/_deps/inherits.mjs +0 -57
- package/dist/_chunks/_deps/is-core-module.mjs +0 -596
- package/dist/_chunks/_deps/is-module.mjs +0 -25
- package/dist/_chunks/_deps/is-reference.mjs +0 -31
- package/dist/_chunks/_deps/klona.mjs +0 -137
- package/dist/_chunks/_deps/knitwork.mjs +0 -172
- package/dist/_chunks/_deps/local-pkg.mjs +0 -163
- package/dist/_chunks/_deps/mime-db.mjs +0 -11685
- package/dist/_chunks/_deps/mime-types.mjs +0 -287
- package/dist/_chunks/_deps/mime.mjs +0 -1172
- package/dist/_chunks/_deps/mlly.mjs +0 -2413
- package/dist/_chunks/_deps/ms.mjs +0 -172
- package/dist/_chunks/_deps/node-fetch-native.mjs +0 -3
- package/dist/_chunks/_deps/nypm.mjs +0 -219
- package/dist/_chunks/_deps/on-finished.mjs +0 -246
- package/dist/_chunks/_deps/parseurl.mjs +0 -168
- package/dist/_chunks/_deps/path-parse.mjs +0 -85
- package/dist/_chunks/_deps/pathe.mjs +0 -251
- package/dist/_chunks/_deps/perfect-debounce.mjs +0 -88
- package/dist/_chunks/_deps/picomatch.mjs +0 -2144
- package/dist/_chunks/_deps/pkg-types.mjs +0 -247
- package/dist/_chunks/_deps/pretty-bytes.mjs +0 -180
- package/dist/_chunks/_deps/quansync.mjs +0 -99
- package/dist/_chunks/_deps/range-parser.mjs +0 -171
- package/dist/_chunks/_deps/rc9.mjs +0 -219
- package/dist/_chunks/_deps/readdirp.mjs +0 -245
- package/dist/_chunks/_deps/resolve.mjs +0 -1260
- package/dist/_chunks/_deps/send.mjs +0 -1022
- package/dist/_chunks/_deps/serve-static.mjs +0 -228
- package/dist/_chunks/_deps/setprototypeof.mjs +0 -26
- package/dist/_chunks/_deps/statuses.mjs +0 -457
- package/dist/_chunks/_deps/std-env.mjs +0 -3
- package/dist/_chunks/_deps/strip-literal.mjs +0 -67
- package/dist/_chunks/_deps/supports-color.mjs +0 -44
- package/dist/_chunks/_deps/tinyexec.mjs +0 -552
- package/dist/_chunks/_deps/toidentifier.mjs +0 -41
- package/dist/_chunks/_deps/ultrahtml.mjs +0 -3
- package/dist/_chunks/_deps/unimport.mjs +0 -2267
- package/dist/_chunks/_deps/unplugin-utils.mjs +0 -65
- package/dist/_chunks/_deps/unplugin.mjs +0 -1294
- package/dist/_chunks/_deps/untyped.mjs +0 -375
- package/dist/_chunks/_deps/unwasm.mjs +0 -6959
- package/dist/_chunks/_deps/webpack-virtual-modules.mjs +0 -360
- package/dist/_chunks/_presets/_all.mjs +0 -59
- package/dist/_chunks/_presets/_nitro.mjs +0 -74
- package/dist/_chunks/_presets/_resolve.mjs +0 -64
- package/dist/_chunks/_presets/_static.mjs +0 -69
- package/dist/_chunks/_presets/_types.mjs +0 -3
- package/dist/_chunks/_presets/_utils.mjs +0 -31
- package/dist/_chunks/_presets/alwaysdata.mjs +0 -17
- package/dist/_chunks/_presets/aws-amplify.mjs +0 -111
- package/dist/_chunks/_presets/aws-lambda.mjs +0 -23
- package/dist/_chunks/_presets/azure.mjs +0 -162
- package/dist/_chunks/_presets/bun.mjs +0 -19
- package/dist/_chunks/_presets/cleavr.mjs +0 -15
- package/dist/_chunks/_presets/cloudflare.mjs +0 -608
- package/dist/_chunks/_presets/deno.mjs +0 -196
- package/dist/_chunks/_presets/digitalocean.mjs +0 -14
- package/dist/_chunks/_presets/firebase.mjs +0 -47
- package/dist/_chunks/_presets/flightcontrol.mjs +0 -14
- package/dist/_chunks/_presets/genezio.mjs +0 -13
- package/dist/_chunks/_presets/heroku.mjs +0 -14
- package/dist/_chunks/_presets/iis.mjs +0 -194
- package/dist/_chunks/_presets/index.mjs +0 -62
- package/dist/_chunks/_presets/koyeb.mjs +0 -14
- package/dist/_chunks/_presets/netlify.mjs +0 -241
- package/dist/_chunks/_presets/node.mjs +0 -54
- package/dist/_chunks/_presets/platform.mjs +0 -14
- package/dist/_chunks/_presets/render.mjs +0 -14
- package/dist/_chunks/_presets/standard.mjs +0 -23
- package/dist/_chunks/_presets/stormkit.mjs +0 -18
- package/dist/_chunks/_presets/vercel.mjs +0 -375
- package/dist/_chunks/_presets/winterjs.mjs +0 -22
- package/dist/_chunks/_presets/zeabur.mjs +0 -69
- package/dist/_chunks/_presets/zerops.mjs +0 -27
- package/dist/_chunks/app.mjs +0 -600
- package/dist/_chunks/builder.mjs +0 -648
- package/dist/_chunks/server.mjs +0 -256
- package/dist/_cli/build.mjs +0 -49
- package/dist/_cli/common.mjs +0 -13
- package/dist/_cli/dev.mjs +0 -121
- package/dist/_cli/index.mjs +0 -16
- package/dist/_cli/list.mjs +0 -33
- package/dist/_cli/prepare.mjs +0 -23
- package/dist/_cli/run.mjs +0 -59
- package/dist/presets/cloudflare/runtime/shims/workers.dev.d.mts +0 -21
- package/dist/runtime/internal/empty.d.mts +0 -0
- package/dist/runtime/internal/vite/dev-entry.d.mts +0 -1
- package/dist/runtime/internal/vite/dev-worker.d.mts +0 -1
- package/dist/runtime/internal/vite/prod-setup.d.mts +0 -4
- package/dist/runtime/internal/vite/ssr-renderer.d.mts +0 -4
- /package/lib/{indexd.mts → index.d.mts} +0 -0
package/dist/_chunks/app.mjs
DELETED
|
@@ -1,600 +0,0 @@
|
|
|
1
|
-
import { existsSync } from 'node:fs';
|
|
2
|
-
import { rm, readFile } from 'node:fs/promises';
|
|
3
|
-
import { Worker } from 'node:worker_threads';
|
|
4
|
-
import consola from 'consola';
|
|
5
|
-
import { a, T } from './_deps/std-env.mjs';
|
|
6
|
-
import { fromNodeHandler, HTTPError, defineHandler, getRequestIP, getRequestURL, H3, toEventHandler, withBase } from 'h3';
|
|
7
|
-
import { s as serveStatic } from './_deps/serve-static.mjs';
|
|
8
|
-
import { joinURL } from 'ufo';
|
|
9
|
-
import { c as createProxyServer } from './_deps/httpxy.mjs';
|
|
10
|
-
import { Agent } from 'undici';
|
|
11
|
-
import { resolve, dirname } from 'node:path';
|
|
12
|
-
import { ErrorParser } from 'youch-core';
|
|
13
|
-
import { Youch } from 'youch';
|
|
14
|
-
import { SourceMapConsumer } from 'source-map';
|
|
15
|
-
import { FastResponse } from 'srvx';
|
|
16
|
-
|
|
17
|
-
function createHTTPProxy(defaults = {}) {
|
|
18
|
-
const proxy = createProxyServer(defaults);
|
|
19
|
-
proxy.on("proxyReq", (proxyReq, req) => {
|
|
20
|
-
if (!proxyReq.hasHeader("x-forwarded-for")) {
|
|
21
|
-
const address = req.socket.remoteAddress;
|
|
22
|
-
if (address) {
|
|
23
|
-
proxyReq.appendHeader("x-forwarded-for", address);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
if (!proxyReq.hasHeader("x-forwarded-port")) {
|
|
27
|
-
const localPort = req?.socket?.localPort;
|
|
28
|
-
if (localPort) {
|
|
29
|
-
proxyReq.setHeader("x-forwarded-port", req.socket.localPort);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
if (!proxyReq.hasHeader("x-forwarded-Proto")) {
|
|
33
|
-
const encrypted = req?.connection?.encrypted;
|
|
34
|
-
proxyReq.setHeader("x-forwarded-proto", encrypted ? "https" : "http");
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
return {
|
|
38
|
-
proxy,
|
|
39
|
-
async handleEvent(event, opts) {
|
|
40
|
-
try {
|
|
41
|
-
return await fromNodeHandler(
|
|
42
|
-
(req, res) => proxy.web(req, res, opts)
|
|
43
|
-
)(event);
|
|
44
|
-
} catch (error) {
|
|
45
|
-
event.res.headers.set("refresh", "3");
|
|
46
|
-
throw new HTTPError({
|
|
47
|
-
status: 503,
|
|
48
|
-
message: "Dev server is unavailable.",
|
|
49
|
-
cause: error
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
function fetchAddress(addr, input, inputInit) {
|
|
56
|
-
let url;
|
|
57
|
-
let init;
|
|
58
|
-
if (input instanceof Request) {
|
|
59
|
-
url = new URL(input.url);
|
|
60
|
-
init = {
|
|
61
|
-
method: input.method,
|
|
62
|
-
headers: input.headers,
|
|
63
|
-
body: input.body,
|
|
64
|
-
...inputInit
|
|
65
|
-
};
|
|
66
|
-
} else {
|
|
67
|
-
url = new URL(input);
|
|
68
|
-
init = inputInit;
|
|
69
|
-
}
|
|
70
|
-
init = {
|
|
71
|
-
duplex: "half",
|
|
72
|
-
redirect: "manual",
|
|
73
|
-
...init
|
|
74
|
-
};
|
|
75
|
-
if (addr.socketPath) {
|
|
76
|
-
url.protocol = "http:";
|
|
77
|
-
return fetch(url, {
|
|
78
|
-
...init,
|
|
79
|
-
...fetchSocketOptions(addr.socketPath)
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
const origin = `http://${addr.host}${addr.port ? `:${addr.port}` : ""}`;
|
|
83
|
-
const outURL = new URL(url.pathname + url.search, origin);
|
|
84
|
-
return fetch(outURL, init);
|
|
85
|
-
}
|
|
86
|
-
function fetchSocketOptions(socketPath) {
|
|
87
|
-
if ("Bun" in globalThis) {
|
|
88
|
-
return { unix: socketPath };
|
|
89
|
-
}
|
|
90
|
-
if ("Deno" in globalThis) {
|
|
91
|
-
return {
|
|
92
|
-
// @ts-ignore
|
|
93
|
-
client: Deno.createHttpClient({
|
|
94
|
-
// @ts-ignore Missing types?
|
|
95
|
-
transport: "unix",
|
|
96
|
-
path: socketPath
|
|
97
|
-
})
|
|
98
|
-
};
|
|
99
|
-
}
|
|
100
|
-
return {
|
|
101
|
-
dispatcher: new Agent({ connect: { socketPath } })
|
|
102
|
-
};
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
class NodeDevWorker {
|
|
106
|
-
closed = false;
|
|
107
|
-
#name;
|
|
108
|
-
#entry;
|
|
109
|
-
#data;
|
|
110
|
-
#hooks;
|
|
111
|
-
#worker;
|
|
112
|
-
#address;
|
|
113
|
-
#proxy;
|
|
114
|
-
#messageListeners;
|
|
115
|
-
constructor(opts) {
|
|
116
|
-
this.#name = opts.name;
|
|
117
|
-
this.#entry = opts.entry;
|
|
118
|
-
this.#data = opts.data;
|
|
119
|
-
this.#hooks = opts.hooks;
|
|
120
|
-
this.#proxy = createHTTPProxy();
|
|
121
|
-
this.#messageListeners = /* @__PURE__ */ new Set();
|
|
122
|
-
this.#initWorker();
|
|
123
|
-
}
|
|
124
|
-
get ready() {
|
|
125
|
-
return Boolean(
|
|
126
|
-
!this.closed && this.#address && this.#proxy && this.#worker
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
// #region Public methods
|
|
130
|
-
async fetch(input, init) {
|
|
131
|
-
for (let i = 0; i < 5 && !(this.#address && this.#proxy); i++) {
|
|
132
|
-
await new Promise((r) => setTimeout(r, 100 * Math.pow(2, i)));
|
|
133
|
-
}
|
|
134
|
-
if (!(this.#address && this.#proxy)) {
|
|
135
|
-
return new Response("Dev worker is unavailable", { status: 503 });
|
|
136
|
-
}
|
|
137
|
-
return fetchAddress(this.#address, input, init);
|
|
138
|
-
}
|
|
139
|
-
upgrade(req, socket, head) {
|
|
140
|
-
if (!this.ready) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
return this.#proxy.proxy.ws(
|
|
144
|
-
req,
|
|
145
|
-
socket,
|
|
146
|
-
{ target: this.#address, xfwd: true },
|
|
147
|
-
head
|
|
148
|
-
);
|
|
149
|
-
}
|
|
150
|
-
sendMessage(message) {
|
|
151
|
-
if (!this.#worker) {
|
|
152
|
-
throw new Error(
|
|
153
|
-
"Dev worker should be initialized before sending messages."
|
|
154
|
-
);
|
|
155
|
-
}
|
|
156
|
-
this.#worker.postMessage(message);
|
|
157
|
-
}
|
|
158
|
-
onMessage(listener) {
|
|
159
|
-
this.#messageListeners.add(listener);
|
|
160
|
-
}
|
|
161
|
-
offMessage(listener) {
|
|
162
|
-
this.#messageListeners.delete(listener);
|
|
163
|
-
}
|
|
164
|
-
async close(cause) {
|
|
165
|
-
if (this.closed) {
|
|
166
|
-
return;
|
|
167
|
-
}
|
|
168
|
-
this.closed = true;
|
|
169
|
-
this.#hooks.onClose?.(this, cause);
|
|
170
|
-
this.#hooks = {};
|
|
171
|
-
const onError = (error) => consola.error(error);
|
|
172
|
-
await this.#closeWorker().catch(onError);
|
|
173
|
-
await this.#closeProxy().catch(onError);
|
|
174
|
-
await this.#closeSocket().catch(onError);
|
|
175
|
-
}
|
|
176
|
-
[Symbol.for("nodejs.util.inspect.custom")]() {
|
|
177
|
-
const status = this.closed ? "closed" : this.ready ? "ready" : "pending";
|
|
178
|
-
return `NodeDevWorker#${this.#name}(${status})`;
|
|
179
|
-
}
|
|
180
|
-
// #endregion
|
|
181
|
-
// #region Private methods
|
|
182
|
-
#initWorker() {
|
|
183
|
-
if (!existsSync(this.#entry)) {
|
|
184
|
-
this.close(`worker entry not found in "${this.#entry}".`);
|
|
185
|
-
return;
|
|
186
|
-
}
|
|
187
|
-
const worker = new Worker(this.#entry, {
|
|
188
|
-
env: {
|
|
189
|
-
...process.env
|
|
190
|
-
},
|
|
191
|
-
workerData: {
|
|
192
|
-
name: this.#name,
|
|
193
|
-
...this.#data
|
|
194
|
-
}
|
|
195
|
-
});
|
|
196
|
-
worker.once("exit", (code) => {
|
|
197
|
-
worker._exitCode = code;
|
|
198
|
-
this.close(`worker exited with code ${code}`);
|
|
199
|
-
});
|
|
200
|
-
worker.once("error", (error) => {
|
|
201
|
-
consola.error(`Worker error:`, error);
|
|
202
|
-
this.close(error);
|
|
203
|
-
});
|
|
204
|
-
worker.on("message", (message) => {
|
|
205
|
-
if (message?.address) {
|
|
206
|
-
this.#address = message.address;
|
|
207
|
-
this.#hooks.onReady?.(this, this.#address);
|
|
208
|
-
}
|
|
209
|
-
for (const listener of this.#messageListeners) {
|
|
210
|
-
listener(message);
|
|
211
|
-
}
|
|
212
|
-
});
|
|
213
|
-
this.#worker = worker;
|
|
214
|
-
}
|
|
215
|
-
async #closeProxy() {
|
|
216
|
-
this.#proxy?.proxy?.close(() => {
|
|
217
|
-
});
|
|
218
|
-
this.#proxy = void 0;
|
|
219
|
-
}
|
|
220
|
-
async #closeSocket() {
|
|
221
|
-
const socketPath = this.#address?.socketPath;
|
|
222
|
-
if (socketPath && socketPath[0] !== "\0" && !socketPath.startsWith(String.raw`\\.\pipe`)) {
|
|
223
|
-
await rm(socketPath).catch(() => {
|
|
224
|
-
});
|
|
225
|
-
}
|
|
226
|
-
this.#address = void 0;
|
|
227
|
-
}
|
|
228
|
-
async #closeWorker() {
|
|
229
|
-
if (!this.#worker) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
this.#worker.postMessage({ event: "shutdown" });
|
|
233
|
-
if (!this.#worker._exitCode && !a && !T) {
|
|
234
|
-
await new Promise((resolve) => {
|
|
235
|
-
const gracefulShutdownTimeoutMs = Number.parseInt(process.env.NITRO_SHUTDOWN_TIMEOUT || "", 10) || 5e3;
|
|
236
|
-
const timeout = setTimeout(() => {
|
|
237
|
-
if (process.env.DEBUG) {
|
|
238
|
-
consola.warn(`force closing dev worker...`);
|
|
239
|
-
}
|
|
240
|
-
}, gracefulShutdownTimeoutMs);
|
|
241
|
-
this.#worker?.on("message", (message) => {
|
|
242
|
-
if (message.event === "exit") {
|
|
243
|
-
clearTimeout(timeout);
|
|
244
|
-
resolve();
|
|
245
|
-
}
|
|
246
|
-
});
|
|
247
|
-
});
|
|
248
|
-
}
|
|
249
|
-
this.#worker.removeAllListeners();
|
|
250
|
-
await this.#worker.terminate().catch((error) => {
|
|
251
|
-
consola.error(error);
|
|
252
|
-
});
|
|
253
|
-
this.#worker = void 0;
|
|
254
|
-
}
|
|
255
|
-
// #endregion
|
|
256
|
-
}
|
|
257
|
-
|
|
258
|
-
function createVFSHandler(nitro) {
|
|
259
|
-
return defineHandler(async (event) => {
|
|
260
|
-
const { socket } = event.runtime?.node?.req || {};
|
|
261
|
-
const isUnixSocket = (
|
|
262
|
-
// No network addresses
|
|
263
|
-
!socket?.remoteAddress && !socket?.localAddress && // Empty address object
|
|
264
|
-
Object.keys(socket?.address?.() || {}).length === 0 && // Socket is readable/writable but has no port info
|
|
265
|
-
socket?.readable && socket?.writable && !socket?.remotePort
|
|
266
|
-
);
|
|
267
|
-
const ip = getRequestIP(event, { xForwardedFor: isUnixSocket });
|
|
268
|
-
const isLocalRequest = ip && /^::1$|^127\.\d+\.\d+\.\d+$/.test(ip);
|
|
269
|
-
if (!isLocalRequest) {
|
|
270
|
-
throw new HTTPError({
|
|
271
|
-
statusText: `Forbidden IP: "${ip || "?"}"`,
|
|
272
|
-
status: 403
|
|
273
|
-
});
|
|
274
|
-
}
|
|
275
|
-
const vfsEntries = {
|
|
276
|
-
...nitro.vfs,
|
|
277
|
-
...nitro.options.virtual
|
|
278
|
-
};
|
|
279
|
-
const url = event.context.params?._ || "";
|
|
280
|
-
const isJson = url.endsWith(".json") || event.req.headers.get("accept")?.includes("application/json");
|
|
281
|
-
const id = decodeURIComponent(url.replace(/^(\.json)?\/?/, "") || "");
|
|
282
|
-
if (id && !(id in vfsEntries)) {
|
|
283
|
-
throw new HTTPError({ message: "File not found", status: 404 });
|
|
284
|
-
}
|
|
285
|
-
let content = id ? vfsEntries[id] : void 0;
|
|
286
|
-
if (typeof content === "function") {
|
|
287
|
-
content = await content();
|
|
288
|
-
}
|
|
289
|
-
if (isJson) {
|
|
290
|
-
return {
|
|
291
|
-
rootDir: nitro.options.rootDir,
|
|
292
|
-
entries: Object.keys(vfsEntries).map((id2) => ({
|
|
293
|
-
id: id2,
|
|
294
|
-
path: "/_vfs.json/" + encodeURIComponent(id2)
|
|
295
|
-
})),
|
|
296
|
-
current: id ? {
|
|
297
|
-
id,
|
|
298
|
-
content
|
|
299
|
-
} : null
|
|
300
|
-
};
|
|
301
|
-
}
|
|
302
|
-
const directories = { [nitro.options.rootDir]: {} };
|
|
303
|
-
const fpaths = Object.keys(vfsEntries);
|
|
304
|
-
for (const item of fpaths) {
|
|
305
|
-
const segments = item.replace(nitro.options.rootDir, "").split("/").filter(Boolean);
|
|
306
|
-
let currentDir = item.startsWith(nitro.options.rootDir) ? directories[nitro.options.rootDir] : directories;
|
|
307
|
-
for (const segment of segments) {
|
|
308
|
-
if (!currentDir[segment]) {
|
|
309
|
-
currentDir[segment] = {};
|
|
310
|
-
}
|
|
311
|
-
currentDir = currentDir[segment];
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
const generateHTML = (directory, path = []) => Object.entries(directory).map(([fname, value = {}]) => {
|
|
315
|
-
const subpath = [...path, fname];
|
|
316
|
-
const key = subpath.join("/");
|
|
317
|
-
const encodedUrl = encodeURIComponent(key);
|
|
318
|
-
const linkClass = url === `/${encodedUrl}` ? "bg-gray-700 text-white" : "hover:bg-gray-800 text-gray-200";
|
|
319
|
-
return Object.keys(value).length === 0 ? `
|
|
320
|
-
<li class="flex flex-nowrap">
|
|
321
|
-
<a href="/_vfs/${encodedUrl}" class="w-full text-sm px-2 py-1 border-b border-gray-10 ${linkClass}">
|
|
322
|
-
${fname}
|
|
323
|
-
</a>
|
|
324
|
-
</li>
|
|
325
|
-
` : `
|
|
326
|
-
<li>
|
|
327
|
-
<details ${url.startsWith(`/${encodedUrl}`) ? "open" : ""}>
|
|
328
|
-
<summary class="w-full text-sm px-2 py-1 border-b border-gray-10 hover:bg-gray-800 text-gray-200">
|
|
329
|
-
${fname}
|
|
330
|
-
</summary>
|
|
331
|
-
<ul class="ml-4">
|
|
332
|
-
${generateHTML(value, subpath)}
|
|
333
|
-
</ul>
|
|
334
|
-
</details>
|
|
335
|
-
</li>
|
|
336
|
-
`;
|
|
337
|
-
}).join("");
|
|
338
|
-
const rootDirectory = directories[nitro.options.rootDir];
|
|
339
|
-
delete directories[nitro.options.rootDir];
|
|
340
|
-
const items = generateHTML(rootDirectory, [nitro.options.rootDir]) + generateHTML(directories);
|
|
341
|
-
const files = `
|
|
342
|
-
<div class="h-full overflow-auto border-r border-gray:10">
|
|
343
|
-
<p class="text-white text-bold text-center py-1 opacity-50">Virtual Files</p>
|
|
344
|
-
<ul class="flex flex-col">${items}</ul>
|
|
345
|
-
</div>
|
|
346
|
-
`;
|
|
347
|
-
const file = id ? editorTemplate({
|
|
348
|
-
readOnly: true,
|
|
349
|
-
language: id.endsWith("html") ? "html" : "javascript",
|
|
350
|
-
theme: "vs-dark",
|
|
351
|
-
value: content,
|
|
352
|
-
wordWrap: "wordWrapColumn",
|
|
353
|
-
wordWrapColumn: 80
|
|
354
|
-
}) : `
|
|
355
|
-
<div class="w-full h-full flex opacity-50">
|
|
356
|
-
<h1 class="text-white m-auto">Select a virtual file to inspect</h1>
|
|
357
|
-
</div>
|
|
358
|
-
`;
|
|
359
|
-
event.res.headers.set("Content-Type", "text/html; charset=utf-8");
|
|
360
|
-
return (
|
|
361
|
-
/* html */
|
|
362
|
-
`
|
|
363
|
-
<!doctype html>
|
|
364
|
-
<html>
|
|
365
|
-
<head>
|
|
366
|
-
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@unocss/reset/tailwind.min.css" />
|
|
367
|
-
<link rel="stylesheet" data-name="vs/editor/editor.main" href="${vsUrl}/editor/editor.main.min.css">
|
|
368
|
-
<script src="https://cdn.jsdelivr.net/npm/@unocss/runtime"><\/script>
|
|
369
|
-
<style>
|
|
370
|
-
html {
|
|
371
|
-
background: #1E1E1E;
|
|
372
|
-
color: white;
|
|
373
|
-
}
|
|
374
|
-
[un-cloak] {
|
|
375
|
-
display: none;
|
|
376
|
-
}
|
|
377
|
-
</style>
|
|
378
|
-
</head>
|
|
379
|
-
<body class="bg-[#1E1E1E]">
|
|
380
|
-
<div un-cloak class="h-screen grid grid-cols-[300px_1fr]">
|
|
381
|
-
${files}
|
|
382
|
-
${file}
|
|
383
|
-
</div>
|
|
384
|
-
</body>
|
|
385
|
-
</html>`
|
|
386
|
-
);
|
|
387
|
-
});
|
|
388
|
-
}
|
|
389
|
-
const monacoVersion = "0.30.0";
|
|
390
|
-
const monacoUrl = `https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/${monacoVersion}/min`;
|
|
391
|
-
const vsUrl = `${monacoUrl}/vs`;
|
|
392
|
-
const editorTemplate = (options) => `
|
|
393
|
-
<div id="editor" class="min-h-screen w-full h-full"></div>
|
|
394
|
-
<script src="${vsUrl}/loader.min.js"><\/script>
|
|
395
|
-
<script>
|
|
396
|
-
require.config({ paths: { vs: '${vsUrl}' } })
|
|
397
|
-
|
|
398
|
-
const proxy = URL.createObjectURL(new Blob([\`
|
|
399
|
-
self.MonacoEnvironment = { baseUrl: '${monacoUrl}' }
|
|
400
|
-
importScripts('${vsUrl}/base/worker/workerMain.min.js')
|
|
401
|
-
\`], { type: 'text/javascript' }))
|
|
402
|
-
window.MonacoEnvironment = { getWorkerUrl: () => proxy }
|
|
403
|
-
|
|
404
|
-
setTimeout(() => {
|
|
405
|
-
require(['vs/editor/editor.main'], function () {
|
|
406
|
-
monaco.editor.create(document.getElementById('editor'), ${JSON.stringify(
|
|
407
|
-
options
|
|
408
|
-
)})
|
|
409
|
-
})
|
|
410
|
-
}, 0);
|
|
411
|
-
<\/script>
|
|
412
|
-
`;
|
|
413
|
-
|
|
414
|
-
function defineNitroErrorHandler(handler) {
|
|
415
|
-
return handler;
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
const devErrorHandler = defineNitroErrorHandler(
|
|
419
|
-
async function defaultNitroErrorHandler(error, event) {
|
|
420
|
-
const res = await defaultHandler(error, event);
|
|
421
|
-
return new FastResponse(
|
|
422
|
-
typeof res.body === "string" ? res.body : JSON.stringify(res.body, null, 2),
|
|
423
|
-
res
|
|
424
|
-
);
|
|
425
|
-
}
|
|
426
|
-
);
|
|
427
|
-
async function defaultHandler(error, event, opts) {
|
|
428
|
-
const isSensitive = error.unhandled;
|
|
429
|
-
const status = error.status || 500;
|
|
430
|
-
const url = getRequestURL(event, { xForwardedHost: true, xForwardedProto: true });
|
|
431
|
-
if (status === 404) {
|
|
432
|
-
const baseURL = import.meta.baseURL || "/";
|
|
433
|
-
if (/^\/[^/]/.test(baseURL) && !url.pathname.startsWith(baseURL)) {
|
|
434
|
-
const redirectTo = `${baseURL}${url.pathname.slice(1)}${url.search}`;
|
|
435
|
-
return {
|
|
436
|
-
status: 302,
|
|
437
|
-
statusText: "Found",
|
|
438
|
-
headers: { location: redirectTo },
|
|
439
|
-
body: `Redirecting...`
|
|
440
|
-
};
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
await loadStackTrace(error).catch(consola.error);
|
|
444
|
-
const youch = new Youch();
|
|
445
|
-
if (isSensitive && !opts?.silent) {
|
|
446
|
-
const tags = [error.unhandled && "[unhandled]"].filter(Boolean).join(" ");
|
|
447
|
-
const ansiError = await (await youch.toANSI(error)).replaceAll(process.cwd(), ".");
|
|
448
|
-
consola.error(
|
|
449
|
-
`[request error] ${tags} [${event.req.method}] ${url}
|
|
450
|
-
|
|
451
|
-
`,
|
|
452
|
-
ansiError
|
|
453
|
-
);
|
|
454
|
-
}
|
|
455
|
-
const useJSON = opts?.json || !event.req.headers.get("accept")?.includes("text/html");
|
|
456
|
-
const headers = {
|
|
457
|
-
"content-type": useJSON ? "application/json" : "text/html",
|
|
458
|
-
// Prevent browser from guessing the MIME types of resources.
|
|
459
|
-
"x-content-type-options": "nosniff",
|
|
460
|
-
// Prevent error page from being embedded in an iframe
|
|
461
|
-
"x-frame-options": "DENY",
|
|
462
|
-
// Prevent browsers from sending the Referer header
|
|
463
|
-
"referrer-policy": "no-referrer",
|
|
464
|
-
// Disable the execution of any js
|
|
465
|
-
"content-security-policy": "script-src 'self' 'unsafe-inline'; object-src 'none'; base-uri 'self';"
|
|
466
|
-
};
|
|
467
|
-
if (status === 404 || !event.res.headers.has("cache-control")) {
|
|
468
|
-
headers["cache-control"] = "no-cache";
|
|
469
|
-
}
|
|
470
|
-
const body = useJSON ? {
|
|
471
|
-
error: true,
|
|
472
|
-
url,
|
|
473
|
-
status,
|
|
474
|
-
statusText: error.statusText,
|
|
475
|
-
message: error.message,
|
|
476
|
-
data: error.data,
|
|
477
|
-
stack: error.stack?.split("\n").map((line) => line.trim())
|
|
478
|
-
} : await youch.toHTML(error, {
|
|
479
|
-
request: {
|
|
480
|
-
url: url.href,
|
|
481
|
-
method: event.req.method,
|
|
482
|
-
headers: Object.fromEntries(event.req.headers.entries())
|
|
483
|
-
}
|
|
484
|
-
});
|
|
485
|
-
return {
|
|
486
|
-
status,
|
|
487
|
-
statusText: error.statusText,
|
|
488
|
-
headers,
|
|
489
|
-
body
|
|
490
|
-
};
|
|
491
|
-
}
|
|
492
|
-
async function loadStackTrace(error) {
|
|
493
|
-
if (!(error instanceof Error)) {
|
|
494
|
-
return;
|
|
495
|
-
}
|
|
496
|
-
const parsed = await new ErrorParser().defineSourceLoader(sourceLoader).parse(error);
|
|
497
|
-
const stack = error.message + "\n" + parsed.frames.map((frame) => fmtFrame(frame)).join("\n");
|
|
498
|
-
Object.defineProperty(error, "stack", { value: stack });
|
|
499
|
-
if (error.cause) {
|
|
500
|
-
await loadStackTrace(error.cause).catch(consola.error);
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
async function sourceLoader(frame) {
|
|
504
|
-
if (!frame.fileName || frame.fileType !== "fs" || frame.type === "native") {
|
|
505
|
-
return;
|
|
506
|
-
}
|
|
507
|
-
if (frame.type === "app") {
|
|
508
|
-
const rawSourceMap = await readFile(`${frame.fileName}.map`, "utf8").catch(() => {
|
|
509
|
-
});
|
|
510
|
-
if (rawSourceMap) {
|
|
511
|
-
const consumer = await new SourceMapConsumer(rawSourceMap);
|
|
512
|
-
const originalPosition = consumer.originalPositionFor({ line: frame.lineNumber, column: frame.columnNumber });
|
|
513
|
-
if (originalPosition.source && originalPosition.line) {
|
|
514
|
-
frame.fileName = resolve(dirname(frame.fileName), originalPosition.source);
|
|
515
|
-
frame.lineNumber = originalPosition.line;
|
|
516
|
-
frame.columnNumber = originalPosition.column || 0;
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
}
|
|
520
|
-
const contents = await readFile(frame.fileName, "utf8").catch(() => {
|
|
521
|
-
});
|
|
522
|
-
return contents ? { contents } : void 0;
|
|
523
|
-
}
|
|
524
|
-
function fmtFrame(frame) {
|
|
525
|
-
if (frame.type === "native") {
|
|
526
|
-
return frame.raw;
|
|
527
|
-
}
|
|
528
|
-
const src = `${frame.fileName || ""}:${frame.lineNumber}:${frame.columnNumber})`;
|
|
529
|
-
return frame.functionName ? `at ${frame.functionName} (${src}` : `at ${src}`;
|
|
530
|
-
}
|
|
531
|
-
|
|
532
|
-
class NitroDevApp {
|
|
533
|
-
nitro;
|
|
534
|
-
fetch;
|
|
535
|
-
constructor(nitro, catchAllHandler) {
|
|
536
|
-
this.nitro = nitro;
|
|
537
|
-
const app = this.#createApp(catchAllHandler);
|
|
538
|
-
this.fetch = app.fetch.bind(app);
|
|
539
|
-
}
|
|
540
|
-
#createApp(catchAllHandler) {
|
|
541
|
-
const app = new H3({
|
|
542
|
-
debug: true,
|
|
543
|
-
onError: async (error, event) => {
|
|
544
|
-
const errorHandler = this.nitro.options.devErrorHandler || devErrorHandler;
|
|
545
|
-
await loadStackTrace(error).catch(() => {
|
|
546
|
-
});
|
|
547
|
-
return errorHandler(error, event, {
|
|
548
|
-
defaultHandler: defaultHandler
|
|
549
|
-
});
|
|
550
|
-
}
|
|
551
|
-
});
|
|
552
|
-
for (const h of this.nitro.options.devHandlers) {
|
|
553
|
-
const handler = toEventHandler(h.handler);
|
|
554
|
-
if (!handler) {
|
|
555
|
-
this.nitro.logger.warn("Invalid dev handler:", h);
|
|
556
|
-
continue;
|
|
557
|
-
}
|
|
558
|
-
if (h.middleware || !h.route) {
|
|
559
|
-
if (h.route) {
|
|
560
|
-
app.use(h.route, handler, { method: h.method });
|
|
561
|
-
} else {
|
|
562
|
-
app.use(handler, { method: h.method });
|
|
563
|
-
}
|
|
564
|
-
} else {
|
|
565
|
-
app.on(h.method || "", h.route, handler, { meta: h.meta });
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
app.get("/_vfs/**", createVFSHandler(this.nitro));
|
|
569
|
-
for (const asset of this.nitro.options.publicAssets) {
|
|
570
|
-
const assetRoute = joinURL(
|
|
571
|
-
this.nitro.options.runtimeConfig.app.baseURL,
|
|
572
|
-
asset.baseURL || "/",
|
|
573
|
-
"**"
|
|
574
|
-
);
|
|
575
|
-
let handler = fromNodeHandler(
|
|
576
|
-
// @ts-expect-error (HTTP2 types)
|
|
577
|
-
serveStatic(asset.dir, { dotfiles: "allow" })
|
|
578
|
-
);
|
|
579
|
-
if (asset.baseURL?.length || 0 > 1) {
|
|
580
|
-
handler = withBase(asset.baseURL, handler);
|
|
581
|
-
}
|
|
582
|
-
app.use(assetRoute, handler);
|
|
583
|
-
}
|
|
584
|
-
const routes = Object.keys(this.nitro.options.devProxy).sort().reverse();
|
|
585
|
-
for (const route of routes) {
|
|
586
|
-
let opts = this.nitro.options.devProxy[route];
|
|
587
|
-
if (typeof opts === "string") {
|
|
588
|
-
opts = { target: opts };
|
|
589
|
-
}
|
|
590
|
-
const proxy = createHTTPProxy(opts);
|
|
591
|
-
app.all(route, proxy.handleEvent);
|
|
592
|
-
}
|
|
593
|
-
if (catchAllHandler) {
|
|
594
|
-
app.all("/**", catchAllHandler);
|
|
595
|
-
}
|
|
596
|
-
return app;
|
|
597
|
-
}
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
export { NitroDevApp as N, NodeDevWorker as a };
|