Skip to content

Commit

Permalink
Merge pull request #422 from nksaraf/bump-nitro
Browse files Browse the repository at this point in the history
chore: bump nitro to v2.10.4, h3 to v13.0
  • Loading branch information
nksaraf authored Dec 1, 2024
2 parents 9591adb + 2a29812 commit 95eeef1
Show file tree
Hide file tree
Showing 8 changed files with 1,489 additions and 390 deletions.
5 changes: 5 additions & 0 deletions .changeset/tender-coats-repeat.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@fake-scope/fake-pkg": patch
---

chore: bump nitro to v2.10.4, h3 to v13.0
4 changes: 2 additions & 2 deletions packages/vinxi/lib/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { resolveRouterConfig, routerSchema } from "./router-modes.js";
routers?: import("./router-modes.js").RouterSchemaInput[];
name?:
string;
server?: Omit<import('nitropack').NitroConfig, 'handlers' | 'devHandlers' | 'publicAssets' | 'scanDirs' | 'appConfigFiles' | 'imports' | 'virtual'> & { https?: import('@vinxi/listhen').HTTPSOptions | boolean };
server?: Omit<import('nitropack').NitroConfig, 'handlers' | 'scanDirs' | 'appConfigFiles' | 'imports' | 'virtual' | 'dev' | 'buildDir'> & { https?: import('@vinxi/listhen').HTTPSOptions | boolean };
root?: string
mode?: string
}} AppOptions */
Expand All @@ -21,7 +21,7 @@ import { resolveRouterConfig, routerSchema } from "./router-modes.js";
config: {
name: string;
devtools: boolean;
server: Omit<import('nitropack').NitroConfig, 'handlers' | 'devHandlers' | 'publicAssets' | 'scanDirs' | 'appConfigFiles' | 'imports' | 'virtual'> & { https?: import('@vinxi/listhen').HTTPSOptions | boolean };
server: Omit<import('nitropack').NitroConfig, 'handlers' | 'scanDirs' | 'appConfigFiles' | 'imports' | 'virtual' | 'dev' | 'buildDir'> & { https?: import('@vinxi/listhen').HTTPSOptions | boolean };
routers: import("./router-mode.js").Router[];
root: string;
mode?: string;
Expand Down
4 changes: 2 additions & 2 deletions packages/vinxi/lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ export async function createBuild(app, buildConfig) {
const nitro = await createNitro({
...app.config.server,
dev: false,

compatibilityDate: "2024-12-01",
rootDir: "",
logLevel: +(process.env.NITRO_LOG_LEVEL || 1),

preset:
buildConfig.preset ??
process.env.TARGET ??
Expand Down
53 changes: 53 additions & 0 deletions packages/vinxi/lib/dev-error.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import {
getResponseStatus,
getResponseStatusText,
send,
setResponseHeader,
setResponseStatus,
} from "h3";

function errorHandler(error, event) {
setResponseHeader(event, "Content-Type", "text/html; charset=UTF-8");
setResponseStatus(event, 503, "Server Unavailable");

let body;
let title;
if (error) {
title = `${getResponseStatus(event)} ${getResponseStatusText(event)}`;
body = `<code><pre>${error.stack}</pre></code>`;
} else {
title = "Reloading server...";
body =
"<progress></progress><script>document.querySelector('progress').indeterminate=true</script>";
}

return send(
event,
`<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
${error ? "" : '<meta http-equiv="refresh" content="2">'}
<title>${title}</title>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico/css/pico.min.css">
</head>
<body>
<main class="container">
<article>
<header>
<h2>${title}</h2>
</header>
${body}
<footer>
Check console logs for more information.
</footer>
</article>
</main>
</body>
</html>
`,
);
}

export default errorHandler;
7 changes: 5 additions & 2 deletions packages/vinxi/lib/dev-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { fileURLToPath } from "node:url";

import { consola, withLogger } from "./logger.js";
import { join, normalize } from "./path.js";
import { resolve } from "./resolve.js";

export * from "./router-dev-plugins.js";

Expand Down Expand Up @@ -130,8 +131,9 @@ export async function createDevServer(
const { createNitro, writeTypes } = await import("nitropack");

const nitro = await createNitro({
...app.config.server,
compatibilityDate: "2024-12-01",
rootDir: "",
...app.config.server,
dev: true,
preset: "nitro-dev",
publicAssets: [
Expand Down Expand Up @@ -169,8 +171,9 @@ export async function createDevServer(
(asset) => Boolean(asset),
)
.flat(),
...(app.config.server.devHandlers ?? []),
],
handlers: [...(app.config.server.handlers ?? [])],
// handlers: [...(app.config.server.handlers ?? [])],
plugins: [...(app.config.server.plugins ?? [])],
});

Expand Down
50 changes: 46 additions & 4 deletions packages/vinxi/lib/nitro-dev.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,14 @@ import { listen } from "@vinxi/listhen";
import { watch } from "chokidar";
import wsAdapter from "crossws/adapters/node";
import {
H3Event,
createApp,
eventHandler,
fromNodeMiddleware,
isEvent,
promisifyNodeListener,
toNodeListener,
} from "h3";
import { createHooks } from "hookable";
import httpProxy from "http-proxy";
import { servePlaceholder } from "serve-placeholder";
import serveStatic from "serve-static";
Expand All @@ -19,8 +20,7 @@ import {
createFetch as createLocalFetch,
} from "unenv/runtime/fetch/index";

import { createServerResponse } from "./http-stream.js";
import { resolve } from "./path.js";
import errorHandler from "./dev-error.js";
import { createRouteRulesHandler } from "./route-rules.js";

// import { createVFSHandler } from './vfs'
Expand Down Expand Up @@ -132,8 +132,48 @@ export async function createDevServer(nitro) {
// });
// nitro.hooks.hook("dev:reload", reload);

const hooks = createHooks();

const captureError = (error, context = {}) => {
const promise = hooks
.callHookParallel("error", error, context)
.catch((error_) => {
console.error("Error while capturing another error", error_);
});
if (context.event && isEvent(context.event)) {
const errors = context.event.context.nitro?.errors;
if (errors) {
errors.push({ error, context });
}
if (context.event.waitUntil) {
context.event.waitUntil(promise);
}
}
};

// App
const app = createApp();
const app = createApp({
debug: Boolean(process.env.DEBUG),
onError: (error, event) => {
captureError(error, { event, tags: ["request"] });
return errorHandler(error, event);
},
onRequest: async (event) => {
await hooks.callHook("request", event).catch((error) => {
captureError(error, { event, tags: ["request"] });
});
},
onBeforeResponse: async (event, response) => {
await hooks.callHook("beforeResponse", event, response).catch((error) => {
captureError(error, { event, tags: ["request", "response"] });
});
},
onAfterResponse: async (event, response) => {
await hooks.callHook("afterResponse", event, response).catch((error) => {
captureError(error, { event, tags: ["request", "response"] });
});
},
});

// Create local fetch callers
const localCall = createCall(promisifyNodeListener(toNodeListener(app)));
Expand Down Expand Up @@ -325,6 +365,8 @@ export async function createDevServer(nitro) {
localCall,
localFetch,
close,
hooks,
captureError,
// watcher,
};
}
Expand Down
6 changes: 3 additions & 3 deletions packages/vinxi/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -191,18 +191,18 @@
"chokidar": "^3.5.3",
"citty": "^0.1.4",
"consola": "^3.2.3",
"crossws": "^0.2.4",
"crossws": "^0.3.1",
"dax-sh": "^0.39.1",
"defu": "^6.1.2",
"es-module-lexer": "^1.3.0",
"esbuild": "^0.20.2",
"fast-glob": "^3.3.1",
"get-port-please": "^3.1.1",
"h3": "1.11.1",
"h3": "1.13.0",
"hookable": "^5.5.3",
"http-proxy": "^1.18.1",
"micromatch": "^4.0.5",
"nitropack": "^2.9.1",
"nitropack": "^2.10.4",
"node-fetch-native": "^1.4.0",
"path-to-regexp": "^6.2.1",
"pathe": "^1.1.1",
Expand Down
Loading

0 comments on commit 95eeef1

Please sign in to comment.