h3 0.7.12 → 0.7.13

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
@@ -135,7 +135,12 @@ function defaultContentType(event, type) {
135
135
  function sendRedirect(event, location, code = 302) {
136
136
  event.res.statusCode = code;
137
137
  event.res.setHeader("Location", location);
138
- return send(event, "Redirecting to " + location, MIMES.html);
138
+ const html = `<!DOCTYPE html>
139
+ <html>
140
+ <head><meta http-equiv="refresh" content="0; url=${encodeURI(location)}"></head>
141
+ <body>Redirecting to <a href=${JSON.stringify(location)}>${encodeURI(location)}</a></body>
142
+ </html>`;
143
+ return send(event, html, MIMES.html);
139
144
  }
140
145
  function appendHeader(event, name, value) {
141
146
  let current = event.res.getHeader(name);
@@ -447,8 +452,11 @@ function createAppEventHandler(stack, options) {
447
452
  return send(event, val, MIMES.html);
448
453
  } else if (isStream(val)) {
449
454
  return sendStream(event, val);
455
+ } else if (val === null) {
456
+ event.res.statusCode = 204;
457
+ return send(event);
450
458
  } else if (type === "object" || type === "boolean" || type === "number") {
451
- if (val && val.buffer) {
459
+ if (val.buffer) {
452
460
  return send(event, val);
453
461
  } else if (val instanceof Error) {
454
462
  throw createError(val);
package/dist/index.d.ts CHANGED
@@ -230,7 +230,7 @@ declare function useMethod(event: CompatibilityEvent, defaultMethod?: HTTPMethod
230
230
  declare function isMethod(event: CompatibilityEvent, expected: HTTPMethod | HTTPMethod[], allowHead?: boolean): boolean;
231
231
  declare function assertMethod(event: CompatibilityEvent, expected: HTTPMethod | HTTPMethod[], allowHead?: boolean): void;
232
232
 
233
- declare function send(event: CompatibilityEvent, data: any, type?: string): Promise<void>;
233
+ declare function send(event: CompatibilityEvent, data?: any, type?: string): Promise<void>;
234
234
  declare function defaultContentType(event: CompatibilityEvent, type?: string): void;
235
235
  declare function sendRedirect(event: CompatibilityEvent, location: string, code?: number): Promise<void>;
236
236
  declare function appendHeader(event: CompatibilityEvent, name: string, value: string): void;
package/dist/index.mjs CHANGED
@@ -127,7 +127,12 @@ function defaultContentType(event, type) {
127
127
  function sendRedirect(event, location, code = 302) {
128
128
  event.res.statusCode = code;
129
129
  event.res.setHeader("Location", location);
130
- return send(event, "Redirecting to " + location, MIMES.html);
130
+ const html = `<!DOCTYPE html>
131
+ <html>
132
+ <head><meta http-equiv="refresh" content="0; url=${encodeURI(location)}"></head>
133
+ <body>Redirecting to <a href=${JSON.stringify(location)}>${encodeURI(location)}</a></body>
134
+ </html>`;
135
+ return send(event, html, MIMES.html);
131
136
  }
132
137
  function appendHeader(event, name, value) {
133
138
  let current = event.res.getHeader(name);
@@ -439,8 +444,11 @@ function createAppEventHandler(stack, options) {
439
444
  return send(event, val, MIMES.html);
440
445
  } else if (isStream(val)) {
441
446
  return sendStream(event, val);
447
+ } else if (val === null) {
448
+ event.res.statusCode = 204;
449
+ return send(event);
442
450
  } else if (type === "object" || type === "boolean" || type === "number") {
443
- if (val && val.buffer) {
451
+ if (val.buffer) {
444
452
  return send(event, val);
445
453
  } else if (val instanceof Error) {
446
454
  throw createError(val);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h3",
3
- "version": "0.7.12",
3
+ "version": "0.7.13",
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.5.2",
48
+ "packageManager": "pnpm@7.8.0",
49
49
  "scripts": {
50
50
  "build": "unbuild",
51
51
  "dev": "vitest",