h3 0.7.14 → 0.7.17

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/index.cjs CHANGED
@@ -154,12 +154,13 @@ function defaultContentType(event, type) {
154
154
  }
155
155
  }
156
156
  function sendRedirect(event, location, code = 302) {
157
+ const encodedLoc = encodeURI(location);
157
158
  event.res.statusCode = code;
158
- event.res.setHeader("Location", location);
159
+ event.res.setHeader("Location", encodedLoc);
159
160
  const html = `<!DOCTYPE html>
160
161
  <html>
161
- <head><meta http-equiv="refresh" content="0; url=${encodeURI(location)}"></head>
162
- <body>Redirecting to <a href=${JSON.stringify(location)}>${encodeURI(location)}</a></body>
162
+ <head><meta http-equiv="refresh" content="0; url=${encodedLoc}"></head>
163
+ <body>Redirecting to <a href=${JSON.stringify(encodedLoc)}>${encodedLoc}</a></body>
163
164
  </html>`;
164
165
  return send(event, html, MIMES.html);
165
166
  }
@@ -244,6 +245,18 @@ function createError(input) {
244
245
  return input;
245
246
  }
246
247
  const err = new H3Error(input.message ?? input.statusMessage, input.cause ? { cause: input.cause } : void 0);
248
+ if ("stack" in input) {
249
+ try {
250
+ Object.defineProperty(err, "stack", { get() {
251
+ return input.stack;
252
+ } });
253
+ } catch {
254
+ try {
255
+ err.stack = input.stack;
256
+ } catch {
257
+ }
258
+ }
259
+ }
247
260
  if (input.statusCode) {
248
261
  err.statusCode = input.statusCode;
249
262
  }
@@ -437,12 +450,12 @@ function createApp(options = {}) {
437
450
  if (!isError(_error)) {
438
451
  error.unhandled = true;
439
452
  }
440
- if (error.unhandled || error.fatal) {
441
- console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
442
- }
443
453
  if (options.onError) {
444
454
  await options.onError(error, event);
445
455
  } else {
456
+ if (error.unhandled || error.fatal) {
457
+ console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
458
+ }
446
459
  await sendError(event, error, !!options.debug);
447
460
  }
448
461
  }
@@ -529,7 +542,7 @@ function normalizeLayer(input) {
529
542
  };
530
543
  }
531
544
 
532
- const RouterMethods = ["connect", "delete", "get", "head", "options", "post", "put", "trace"];
545
+ const RouterMethods = ["connect", "delete", "get", "head", "options", "post", "put", "trace", "patch"];
533
546
  function createRouter() {
534
547
  const _router = radix3.createRouter({});
535
548
  const routes = {};
package/dist/index.d.ts CHANGED
@@ -34,7 +34,7 @@ declare function isEvent(input: any): input is H3Event;
34
34
 
35
35
  interface CompatibilityRequestProps {
36
36
  event: H3Event;
37
- context: Record<string, any>;
37
+ context: H3EventContext;
38
38
  /** Only available with connect and press */
39
39
  originalUrl?: string;
40
40
  }
package/dist/index.mjs CHANGED
@@ -146,12 +146,13 @@ function defaultContentType(event, type) {
146
146
  }
147
147
  }
148
148
  function sendRedirect(event, location, code = 302) {
149
+ const encodedLoc = encodeURI(location);
149
150
  event.res.statusCode = code;
150
- event.res.setHeader("Location", location);
151
+ event.res.setHeader("Location", encodedLoc);
151
152
  const html = `<!DOCTYPE html>
152
153
  <html>
153
- <head><meta http-equiv="refresh" content="0; url=${encodeURI(location)}"></head>
154
- <body>Redirecting to <a href=${JSON.stringify(location)}>${encodeURI(location)}</a></body>
154
+ <head><meta http-equiv="refresh" content="0; url=${encodedLoc}"></head>
155
+ <body>Redirecting to <a href=${JSON.stringify(encodedLoc)}>${encodedLoc}</a></body>
155
156
  </html>`;
156
157
  return send(event, html, MIMES.html);
157
158
  }
@@ -236,6 +237,18 @@ function createError(input) {
236
237
  return input;
237
238
  }
238
239
  const err = new H3Error(input.message ?? input.statusMessage, input.cause ? { cause: input.cause } : void 0);
240
+ if ("stack" in input) {
241
+ try {
242
+ Object.defineProperty(err, "stack", { get() {
243
+ return input.stack;
244
+ } });
245
+ } catch {
246
+ try {
247
+ err.stack = input.stack;
248
+ } catch {
249
+ }
250
+ }
251
+ }
239
252
  if (input.statusCode) {
240
253
  err.statusCode = input.statusCode;
241
254
  }
@@ -429,12 +442,12 @@ function createApp(options = {}) {
429
442
  if (!isError(_error)) {
430
443
  error.unhandled = true;
431
444
  }
432
- if (error.unhandled || error.fatal) {
433
- console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
434
- }
435
445
  if (options.onError) {
436
446
  await options.onError(error, event);
437
447
  } else {
448
+ if (error.unhandled || error.fatal) {
449
+ console.error("[h3]", error.fatal ? "[fatal]" : "[unhandled]", error);
450
+ }
438
451
  await sendError(event, error, !!options.debug);
439
452
  }
440
453
  }
@@ -521,7 +534,7 @@ function normalizeLayer(input) {
521
534
  };
522
535
  }
523
536
 
524
- const RouterMethods = ["connect", "delete", "get", "head", "options", "post", "put", "trace"];
537
+ const RouterMethods = ["connect", "delete", "get", "head", "options", "post", "put", "trace", "patch"];
525
538
  function createRouter() {
526
539
  const _router = createRouter$1({});
527
540
  const routes = {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h3",
3
- "version": "0.7.14",
3
+ "version": "0.7.17",
4
4
  "description": "Tiny JavaScript Server",
5
5
  "repository": "unjs/h3",
6
6
  "license": "MIT",
@@ -45,7 +45,7 @@
45
45
  "unbuild": "latest",
46
46
  "vitest": "latest"
47
47
  },
48
- "packageManager": "pnpm@7.9.0",
48
+ "packageManager": "pnpm@7.9.5",
49
49
  "scripts": {
50
50
  "build": "unbuild",
51
51
  "dev": "vitest",