Comparing version 0.2.0 to 0.2.1
@@ -5,5 +5,7 @@ # Changelog | ||
## [0.2.0](https://github.com/nuxt-contrib/h2/compare/v0.0.15...v0.2.0) (2020-12-15) | ||
### [0.2.1](https://github.com/nuxt-contrib/h3/compare/v0.2.0...v0.2.1) (2021-01-12) | ||
## [0.2.0](https://github.com/nuxt-contrib/h3/compare/v0.0.15...v0.2.0) (2020-12-15) | ||
### ⚠ BREAKING CHANGES | ||
@@ -15,7 +17,7 @@ | ||
* `useCookie`, `useCookies` and `setCookie` utilities ([088f413](https://github.com/nuxt-contrib/h2/commit/088f413434a619a9888bfd9d1b189e56a7d00124)), closes [#17](https://github.com/nuxt-contrib/h2/issues/17) | ||
* appendHeader utility ([84be904](https://github.com/nuxt-contrib/h2/commit/84be9040e2c52b625a47591e8f5107793da29f72)) | ||
* rename useBodyJSON to useBody and unexposed cached value ([d8d39a0](https://github.com/nuxt-contrib/h2/commit/d8d39a0eefbc22c8d3af8e7dcee5ee8964da07e3)) | ||
* `useCookie`, `useCookies` and `setCookie` utilities ([088f413](https://github.com/nuxt-contrib/h3/commit/088f413434a619a9888bfd9d1b189e56a7d00124)), closes [#17](https://github.com/nuxt-contrib/h3/issues/17) | ||
* appendHeader utility ([84be904](https://github.com/nuxt-contrib/h3/commit/84be9040e2c52b625a47591e8f5107793da29f72)) | ||
* rename useBodyJSON to useBody and unexposed cached value ([d8d39a0](https://github.com/nuxt-contrib/h3/commit/d8d39a0eefbc22c8d3af8e7dcee5ee8964da07e3)) | ||
### [0.0.15](https://github.com/nuxt-contrib/h2/compare/v0.0.14...v0.0.15) (2020-12-12) | ||
### [0.0.15](https://github.com/nuxt-contrib/h3/compare/v0.0.14...v0.0.15) (2020-12-12) | ||
@@ -25,4 +27,4 @@ | ||
* add request and response utils ([#15](https://github.com/nuxt-contrib/h2/issues/15)) ([648e9b9](https://github.com/nuxt-contrib/h2/commit/648e9b9ceff3a8658a7e3705164d5139e6f95c99)) | ||
* custom error handler ([ad3515f](https://github.com/nuxt-contrib/h2/commit/ad3515f0da8bb37d3f82a6527c459aa86a63e338)) | ||
* add request and response utils ([#15](https://github.com/nuxt-contrib/h3/issues/15)) ([648e9b9](https://github.com/nuxt-contrib/h3/commit/648e9b9ceff3a8658a7e3705164d5139e6f95c99)) | ||
* custom error handler ([ad3515f](https://github.com/nuxt-contrib/h3/commit/ad3515f0da8bb37d3f82a6527c459aa86a63e338)) | ||
@@ -32,7 +34,7 @@ | ||
* don't override internal flag ([a5ee318](https://github.com/nuxt-contrib/h2/commit/a5ee31888101cbe7458d7a63527d0cf07845d2a6)) | ||
* hide 404 error ([38fb027](https://github.com/nuxt-contrib/h2/commit/38fb027bb5a2d3d369f7d3e333edc1342cf32914)) | ||
* preserve error message in console ([3002b27](https://github.com/nuxt-contrib/h2/commit/3002b27aace50cf6d39c289b8500bb92a065fe7a)) | ||
* don't override internal flag ([a5ee318](https://github.com/nuxt-contrib/h3/commit/a5ee31888101cbe7458d7a63527d0cf07845d2a6)) | ||
* hide 404 error ([38fb027](https://github.com/nuxt-contrib/h3/commit/38fb027bb5a2d3d369f7d3e333edc1342cf32914)) | ||
* preserve error message in console ([3002b27](https://github.com/nuxt-contrib/h3/commit/3002b27aace50cf6d39c289b8500bb92a065fe7a)) | ||
### [0.0.14](https://github.com/nuxt-contrib/h2/compare/v0.0.13...v0.0.14) (2020-12-05) | ||
### [0.0.14](https://github.com/nuxt-contrib/h3/compare/v0.0.13...v0.0.14) (2020-12-05) | ||
@@ -42,6 +44,6 @@ | ||
* **app:** handle buffer ([09c9c6d](https://github.com/nuxt-contrib/h2/commit/09c9c6da5bcd00ff49e815cae3c74893d4b4806d)) | ||
* **utils:** avoid setting falsy type ([df5e92b](https://github.com/nuxt-contrib/h2/commit/df5e92b07ca2c096fb078c0deff50b613245c0db)) | ||
* **app:** handle buffer ([09c9c6d](https://github.com/nuxt-contrib/h3/commit/09c9c6da5bcd00ff49e815cae3c74893d4b4806d)) | ||
* **utils:** avoid setting falsy type ([df5e92b](https://github.com/nuxt-contrib/h3/commit/df5e92b07ca2c096fb078c0deff50b613245c0db)) | ||
### [0.0.13](https://github.com/nuxt-contrib/h2/compare/v0.0.12...v0.0.13) (2020-12-05) | ||
### [0.0.13](https://github.com/nuxt-contrib/h3/compare/v0.0.12...v0.0.13) (2020-12-05) | ||
@@ -51,5 +53,5 @@ | ||
* enable debug by default ([010cdfe](https://github.com/nuxt-contrib/h2/commit/010cdfe32ce80b2453489f8839c5f3d946d027a1)) | ||
* enable debug by default ([010cdfe](https://github.com/nuxt-contrib/h3/commit/010cdfe32ce80b2453489f8839c5f3d946d027a1)) | ||
### [0.0.12](https://github.com/nuxt-contrib/h2/compare/v0.0.11...v0.0.12) (2020-11-23) | ||
### [0.0.12](https://github.com/nuxt-contrib/h3/compare/v0.0.11...v0.0.12) (2020-11-23) | ||
@@ -59,3 +61,3 @@ | ||
* allow chaining use statements ([#9](https://github.com/nuxt-contrib/h2/issues/9)) ([e30ea79](https://github.com/nuxt-contrib/h2/commit/e30ea7911ed378866f2c61b0ece3f332e113e821)), closes [#5](https://github.com/nuxt-contrib/h2/issues/5) | ||
* allow chaining use statements ([#9](https://github.com/nuxt-contrib/h3/issues/9)) ([e30ea79](https://github.com/nuxt-contrib/h3/commit/e30ea7911ed378866f2c61b0ece3f332e113e821)), closes [#5](https://github.com/nuxt-contrib/h3/issues/5) | ||
@@ -65,7 +67,7 @@ | ||
* correctly expose route and middleware types ([#10](https://github.com/nuxt-contrib/h2/issues/10)) ([bb6cd4c](https://github.com/nuxt-contrib/h2/commit/bb6cd4c6971fc269d6a313ebc07910898b32f178)), closes [#11](https://github.com/nuxt-contrib/h2/issues/11) [#11](https://github.com/nuxt-contrib/h2/issues/11) | ||
* ensure correct url is used when used as a sub-app ([0e4770a](https://github.com/nuxt-contrib/h2/commit/0e4770af89757c274b1d3e6d7c54b973a7bf9bef)) | ||
* mark app._handle as private to avoid sub-app detection ([1439f35](https://github.com/nuxt-contrib/h2/commit/1439f354a7e9238113f6d8bc7687df8a5fe7bd10)) | ||
* correctly expose route and middleware types ([#10](https://github.com/nuxt-contrib/h3/issues/10)) ([bb6cd4c](https://github.com/nuxt-contrib/h3/commit/bb6cd4c6971fc269d6a313ebc07910898b32f178)), closes [#11](https://github.com/nuxt-contrib/h3/issues/11) [#11](https://github.com/nuxt-contrib/h3/issues/11) | ||
* ensure correct url is used when used as a sub-app ([0e4770a](https://github.com/nuxt-contrib/h3/commit/0e4770af89757c274b1d3e6d7c54b973a7bf9bef)) | ||
* mark app._handle as private to avoid sub-app detection ([1439f35](https://github.com/nuxt-contrib/h3/commit/1439f354a7e9238113f6d8bc7687df8a5fe7bd10)) | ||
### [0.0.11](https://github.com/nuxt-contrib/h2/compare/v0.0.10...v0.0.11) (2020-11-21) | ||
### [0.0.11](https://github.com/nuxt-contrib/h3/compare/v0.0.10...v0.0.11) (2020-11-21) | ||
@@ -75,6 +77,6 @@ | ||
* `useAsync` ([236e979](https://github.com/nuxt-contrib/h2/commit/236e97953ac014dffa8977c4bf8cd6f2fa369eb7)) | ||
* custom matcher and improved docs ([1c4f9d1](https://github.com/nuxt-contrib/h2/commit/1c4f9d138dde212486d1aa7acb0e2df9a8cb8aca)) | ||
* `useAsync` ([236e979](https://github.com/nuxt-contrib/h3/commit/236e97953ac014dffa8977c4bf8cd6f2fa369eb7)) | ||
* custom matcher and improved docs ([1c4f9d1](https://github.com/nuxt-contrib/h3/commit/1c4f9d138dde212486d1aa7acb0e2df9a8cb8aca)) | ||
### [0.0.10](https://github.com/nuxt-contrib/h2/compare/v0.0.9...v0.0.10) (2020-11-20) | ||
### [0.0.10](https://github.com/nuxt-contrib/h3/compare/v0.0.9...v0.0.10) (2020-11-20) | ||
@@ -84,5 +86,5 @@ | ||
* rewrite with much sexier API ([0d3680e](https://github.com/nuxt-contrib/h2/commit/0d3680eacab44d6a40c10b94cfba2036afc571d9)) | ||
* rewrite with much sexier API ([0d3680e](https://github.com/nuxt-contrib/h3/commit/0d3680eacab44d6a40c10b94cfba2036afc571d9)) | ||
### [0.0.9](https://github.com/nuxt-contrib/h2/compare/v0.0.8...v0.0.9) (2020-11-20) | ||
### [0.0.9](https://github.com/nuxt-contrib/h3/compare/v0.0.8...v0.0.9) (2020-11-20) | ||
@@ -92,3 +94,3 @@ | ||
* createError ([1a80bd9](https://github.com/nuxt-contrib/h2/commit/1a80bd9432b0585a474d6888e7035636307eead8)) | ||
* createError ([1a80bd9](https://github.com/nuxt-contrib/h3/commit/1a80bd9432b0585a474d6888e7035636307eead8)) | ||
@@ -98,5 +100,5 @@ | ||
* throw 404 only when writableEnded is not set ([1c42a07](https://github.com/nuxt-contrib/h2/commit/1c42a07e3ecc175c96dff026967298a107314f5e)) | ||
* throw 404 only when writableEnded is not set ([1c42a07](https://github.com/nuxt-contrib/h3/commit/1c42a07e3ecc175c96dff026967298a107314f5e)) | ||
### [0.0.8](https://github.com/nuxt-contrib/h2/compare/v0.0.7...v0.0.8) (2020-11-19) | ||
### [0.0.8](https://github.com/nuxt-contrib/h3/compare/v0.0.7...v0.0.8) (2020-11-19) | ||
@@ -106,7 +108,7 @@ | ||
* don't log 404 ([541ede0](https://github.com/nuxt-contrib/h2/commit/541ede03edc6526b953c8a0bb7f31f0dc5fc21d3)) | ||
* don't log 404 ([541ede0](https://github.com/nuxt-contrib/h3/commit/541ede03edc6526b953c8a0bb7f31f0dc5fc21d3)) | ||
### [0.0.7](https://github.com/nuxt-contrib/h2/compare/v0.0.6...v0.0.7) (2020-11-19) | ||
### [0.0.7](https://github.com/nuxt-contrib/h3/compare/v0.0.6...v0.0.7) (2020-11-19) | ||
### [0.0.6](https://github.com/nuxt-contrib/h2/compare/v0.0.5...v0.0.6) (2020-11-19) | ||
### [0.0.6](https://github.com/nuxt-contrib/h3/compare/v0.0.5...v0.0.6) (2020-11-19) | ||
@@ -116,5 +118,5 @@ | ||
* add debug option to app ([b0891cd](https://github.com/nuxt-contrib/h2/commit/b0891cd13d4a7b8ed0fb981ae878185c6728b618)) | ||
* add debug option to app ([b0891cd](https://github.com/nuxt-contrib/h3/commit/b0891cd13d4a7b8ed0fb981ae878185c6728b618)) | ||
### [0.0.5](https://github.com/nuxt-contrib/h2/compare/v0.0.4...v0.0.5) (2020-11-19) | ||
### [0.0.5](https://github.com/nuxt-contrib/h3/compare/v0.0.4...v0.0.5) (2020-11-19) | ||
@@ -124,5 +126,5 @@ | ||
* expose unsafeHandle ([f1245f1](https://github.com/nuxt-contrib/h2/commit/f1245f13c1a4ec1f9e1ecb4b0b73c50047ee4d3a)) | ||
* expose unsafeHandle ([f1245f1](https://github.com/nuxt-contrib/h3/commit/f1245f13c1a4ec1f9e1ecb4b0b73c50047ee4d3a)) | ||
### [0.0.4](https://github.com/nuxt-contrib/h2/compare/v0.0.3...v0.0.4) (2020-11-19) | ||
### [0.0.4](https://github.com/nuxt-contrib/h3/compare/v0.0.3...v0.0.4) (2020-11-19) | ||
@@ -132,3 +134,3 @@ | ||
* rewrite promisify logic ([a40aa81](https://github.com/nuxt-contrib/h2/commit/a40aa81aa80da3ba418061338bcaa6286357ab67)) | ||
* rewrite promisify logic ([a40aa81](https://github.com/nuxt-contrib/h3/commit/a40aa81aa80da3ba418061338bcaa6286357ab67)) | ||
@@ -138,6 +140,6 @@ | ||
* keep top level trailing slash ([2fb92ef](https://github.com/nuxt-contrib/h2/commit/2fb92efdf462f3c4098af3cac6594599839f7cde)) | ||
* stop middleware when writableEnded flag is set ([d87d8e5](https://github.com/nuxt-contrib/h2/commit/d87d8e5f7a426409565d1a008b8231c793ec61ef)) | ||
* keep top level trailing slash ([2fb92ef](https://github.com/nuxt-contrib/h3/commit/2fb92efdf462f3c4098af3cac6594599839f7cde)) | ||
* stop middleware when writableEnded flag is set ([d87d8e5](https://github.com/nuxt-contrib/h3/commit/d87d8e5f7a426409565d1a008b8231c793ec61ef)) | ||
### [0.0.3](https://github.com/nuxt-contrib/h2/compare/v0.0.2...v0.0.3) (2020-11-19) | ||
### [0.0.3](https://github.com/nuxt-contrib/h3/compare/v0.0.2...v0.0.3) (2020-11-19) | ||
@@ -147,5 +149,5 @@ | ||
* improve error util ([5504f4e](https://github.com/nuxt-contrib/h2/commit/5504f4e53dfb19cceb6580b00077f8c80d0b5dc5)) | ||
* improve error util ([5504f4e](https://github.com/nuxt-contrib/h3/commit/5504f4e53dfb19cceb6580b00077f8c80d0b5dc5)) | ||
### [0.0.2](https://github.com/nuxt-contrib/h2/compare/v0.0.1...v0.0.2) (2020-11-19) | ||
### [0.0.2](https://github.com/nuxt-contrib/h3/compare/v0.0.1...v0.0.2) (2020-11-19) | ||
@@ -155,3 +157,3 @@ | ||
* remove dependency on process.env ([eb018f5](https://github.com/nuxt-contrib/h2/commit/eb018f5e23a5f797a4b5d24fdbfe591994c39aef)) | ||
* remove dependency on process.env ([eb018f5](https://github.com/nuxt-contrib/h3/commit/eb018f5e23a5f797a4b5d24fdbfe591994c39aef)) | ||
@@ -163,4 +165,4 @@ ### 0.0.1 (2020-11-18) | ||
* de-default loazy handles ([0cb8c0c](https://github.com/nuxt-contrib/h2/commit/0cb8c0c74647278806a53f7920f8678bb47749e5)) | ||
* update docs and caller utility ([0ef0020](https://github.com/nuxt-contrib/h2/commit/0ef0020da1931b8c08344008253703b91b318559)) | ||
* de-default loazy handles ([0cb8c0c](https://github.com/nuxt-contrib/h3/commit/0cb8c0c74647278806a53f7920f8678bb47749e5)) | ||
* update docs and caller utility ([0ef0020](https://github.com/nuxt-contrib/h3/commit/0ef0020da1931b8c08344008253703b91b318559)) | ||
@@ -170,3 +172,3 @@ | ||
* **app:** handle returning promise ([2169f92](https://github.com/nuxt-contrib/h2/commit/2169f92142d2e92e143913fff945628f17203779)) | ||
* **writable:** set writableEnded and writableFinished ([7058fdc](https://github.com/nuxt-contrib/h2/commit/7058fdcf38a31edd1ce2afe4b05eb0b050adea78)) | ||
* **app:** handle returning promise ([2169f92](https://github.com/nuxt-contrib/h3/commit/2169f92142d2e92e143913fff945628f17203779)) | ||
* **writable:** set writableEnded and writableFinished ([7058fdc](https://github.com/nuxt-contrib/h3/commit/7058fdcf38a31edd1ce2afe4b05eb0b050adea78)) |
import { IncomingMessage, ServerResponse } from 'http'; | ||
import { SearchParams } from '@nuxt/ufo'; | ||
@@ -57,3 +56,3 @@ declare type Encoding = false | 'ascii' | 'utf8' | 'utf-8' | 'utf16le' | 'ucs2' | 'ucs-2' | 'base64' | 'latin1' | 'binary' | 'hex'; | ||
/** | ||
* H2 Runtime Error | ||
* H3 Runtime Error | ||
* @class | ||
@@ -67,3 +66,3 @@ * @extends Error | ||
*/ | ||
declare class H2Error extends Error { | ||
declare class H3Error extends Error { | ||
statusCode: number; | ||
@@ -77,17 +76,17 @@ statusMessage: string; | ||
* | ||
* @param input {Partial<H2Error>} | ||
* @return {H2Error} An instance of the H2Error | ||
* @param input {Partial<H3Error>} | ||
* @return {H3Error} An instance of the H3Error | ||
*/ | ||
declare function createError(input: Partial<H2Error>): H2Error; | ||
declare function createError(input: Partial<H3Error>): H3Error; | ||
/** | ||
* Recieve an error and return the corresponding response.<br> | ||
* H2 internally uses this fucntion to handle unhandled errors.<br> | ||
* H3 internally uses this fucntion to handle unhandled errors.<br> | ||
* Note that calling this function will close the connection and no other data will be sent to client afterwards. | ||
* | ||
* @param res {ServerResponse} The ServerResponse object is passed as the second parameter in the handler function | ||
* @param error {H2Error|Error} Raised error | ||
* @param error {H3Error|Error} Raised error | ||
* @param debug {Boolean} Whether application is in debug mode.<br> | ||
* In the debug mode the stack trace of errors will be return in response. | ||
*/ | ||
declare function sendError(res: ServerResponse, error: Error | H2Error, debug?: boolean): void; | ||
declare function sendError(res: ServerResponse, error: Error | H3Error, debug?: boolean): void; | ||
@@ -208,3 +207,3 @@ /** | ||
declare function useQuery(req: IncomingMessage): SearchParams; | ||
declare function useQuery(req: IncomingMessage): Record<string, string | string[] | undefined>; | ||
@@ -216,2 +215,2 @@ declare function send(res: ServerResponse, data: any, type?: string): void; | ||
export { App, AppOptions, AppUse, H2Error, Handle, InputLayer, InputStack, Layer, LazyHandle, MIMES, Matcher, Middleware, PHandle, Stack, appendHeader, callHandle, createApp, createError, createHandle, defaultContentType, lazyHandle, promisifyHandle, send, sendError, sendRedirect, setCookie, use, useBase, useBody, useCookie, useCookies, useQuery, useRawBody }; | ||
export { App, AppOptions, AppUse, H3Error, Handle, InputLayer, InputStack, Layer, LazyHandle, MIMES, Matcher, Middleware, PHandle, Stack, appendHeader, callHandle, createApp, createError, createHandle, defaultContentType, lazyHandle, promisifyHandle, send, sendError, sendRedirect, setCookie, use, useBase, useBody, useCookie, useCookies, useQuery, useRawBody }; |
@@ -5,27 +5,68 @@ 'use strict'; | ||
function decode(text = "") { | ||
try { | ||
return decodeURIComponent("" + text); | ||
} catch (_err) { | ||
return "" + text; | ||
} | ||
} | ||
function parseQuery(paramsStr = "") { | ||
const obj = {}; | ||
if (paramsStr[0] === "?") { | ||
paramsStr = paramsStr.substr(1); | ||
} | ||
for (const param of paramsStr.split("&")) { | ||
const s = param.match(/([^=]+)=?(.*)/) || []; | ||
if (s.length < 2) { | ||
continue; | ||
} | ||
const key = decode(s[1]); | ||
const value = decode(s[2] || ""); | ||
if (obj[key]) { | ||
if (Array.isArray(obj[key])) { | ||
obj[key].push(value); | ||
} else { | ||
obj[key] = [obj[key], value]; | ||
} | ||
} else { | ||
obj[key] = value; | ||
} | ||
} | ||
return obj; | ||
} | ||
function hasProtocol(inputStr) { | ||
return /^\w+:\/\//.test(inputStr); | ||
} | ||
function withoutTrailingSlash(input = "") { | ||
return input.endsWith("/") ? input.slice(0, -1) : input; | ||
} | ||
function hasProtocol(inputStr) { | ||
return /\w+:\//.test(inputStr); | ||
function getQuery(input) { | ||
return parseQuery(parseURL(input).search); | ||
} | ||
function parseURL(input = "") { | ||
if (typeof input !== "string") { | ||
if (!input || !input.url) { | ||
throw new Error(`Invalid url: ${JSON.stringify(input)}`); | ||
} | ||
return input; | ||
if (!hasProtocol(input)) { | ||
return parsePath(input); | ||
} | ||
const _hasProtocol = hasProtocol(input); | ||
const isRelative = _hasProtocol ? false : input[0] !== "/"; | ||
const url = new URL(input, _hasProtocol ? void 0 : "default:/"); | ||
return {url, hasProtocol: _hasProtocol, isRelative}; | ||
const [protocol, auth, hostAndPath] = (input.match(/([^:/]+:)\/\/([^/@]+@)?(.*)/) || []).splice(1); | ||
const [host = "", path = ""] = (hostAndPath.match(/([^/]*)(.*)?/) || []).splice(1); | ||
const {pathname, search, hash} = parsePath(path); | ||
return { | ||
protocol, | ||
auth: auth ? auth.substr(0, auth.length - 1) : "", | ||
host, | ||
pathname, | ||
search, | ||
hash | ||
}; | ||
} | ||
function getParams(input) { | ||
const parsed = parseURL(input); | ||
const params = {}; | ||
parsed.url.searchParams.forEach((value, key) => { | ||
params[key] = value; | ||
}); | ||
return params; | ||
function parsePath(input = "") { | ||
const [pathname = "", search = "", hash = ""] = (input.match(/([^#?]*)(\?[^#]*)?(#.*)?/) || []).splice(1); | ||
return { | ||
pathname, | ||
search, | ||
hash | ||
}; | ||
} | ||
@@ -143,4 +184,4 @@ | ||
const RawBodySymbol = Symbol("h2RawBody"); | ||
const ParsedBodySymbol = Symbol("h2RawBody"); | ||
const RawBodySymbol = Symbol("h3RawBody"); | ||
const ParsedBodySymbol = Symbol("h3RawBody"); | ||
function useRawBody(req, encoding = "utf-8") { | ||
@@ -197,3 +238,3 @@ if (req[RawBodySymbol]) { | ||
var decode = decodeURIComponent; | ||
var decode$1 = decodeURIComponent; | ||
var encode = encodeURIComponent; | ||
@@ -232,3 +273,3 @@ var pairSplitRegExp = /; */; | ||
var pairs = str.split(pairSplitRegExp); | ||
var dec = opt.decode || decode; | ||
var dec = opt.decode || decode$1; | ||
@@ -420,6 +461,6 @@ for (var i = 0; i < pairs.length; i++) { | ||
function useQuery(req) { | ||
return getParams(req.url || ""); | ||
return getQuery(req.url || ""); | ||
} | ||
class H2Error extends Error { | ||
class H3Error extends Error { | ||
constructor() { | ||
@@ -433,6 +474,6 @@ super(...arguments); | ||
function createError(input) { | ||
if (input instanceof H2Error) { | ||
if (input instanceof H3Error) { | ||
return input; | ||
} | ||
const err = new H2Error(input.message); | ||
const err = new H3Error(input.message); | ||
if (input.statusCode) { | ||
@@ -453,8 +494,8 @@ err.statusCode = input.statusCode; | ||
function sendError(res, error, debug) { | ||
const h2Error = createError(error); | ||
if (h2Error.internal) { | ||
console.error(h2Error); | ||
const h3Error = createError(error); | ||
if (h3Error.internal) { | ||
console.error(h3Error); | ||
} | ||
res.statusCode = h2Error.statusCode; | ||
res.statusMessage = h2Error.statusMessage; | ||
res.statusCode = h3Error.statusCode; | ||
res.statusMessage = h3Error.statusMessage; | ||
const responseBody = { | ||
@@ -464,6 +505,6 @@ statusCode: res.statusCode, | ||
stack: [], | ||
data: h2Error.data | ||
data: h3Error.data | ||
}; | ||
if (debug) { | ||
responseBody.stack = (h2Error.stack || "").split("\n").map((l) => l.trim()); | ||
responseBody.stack = (h3Error.stack || "").split("\n").map((l) => l.trim()); | ||
} | ||
@@ -552,3 +593,3 @@ res.setHeader("Content-Type", MIMES.json); | ||
exports.H2Error = H2Error; | ||
exports.H3Error = H3Error; | ||
exports.MIMES = MIMES; | ||
@@ -555,0 +596,0 @@ exports.appendHeader = appendHeader; |
{ | ||
"name": "h3", | ||
"version": "0.2.0", | ||
"version": "0.2.1", | ||
"description": "Tiny JavaScript Server", | ||
"repository": "nuxt-contrib/h2", | ||
"repository": "nuxt-contrib/h3", | ||
"license": "MIT", | ||
@@ -22,5 +22,4 @@ "sideEffects": false, | ||
"devDependencies": { | ||
"@nuxt/ufo": "^0.1.3", | ||
"@nuxtjs/eslint-config-typescript": "latest", | ||
"@types/cookie": "^0.4.0", | ||
"@types/cookie": "latest", | ||
"@types/express": "latest", | ||
@@ -30,4 +29,4 @@ "@types/node": "latest", | ||
"connect": "latest", | ||
"cookie": "^0.4.1", | ||
"destr": "^1.0.1", | ||
"cookie": "latest", | ||
"destr": "latest", | ||
"eslint": "latest", | ||
@@ -38,3 +37,3 @@ "express": "latest", | ||
"jiti": "latest", | ||
"listhen": "^0.1.2", | ||
"listhen": "latest", | ||
"siroc": "latest", | ||
@@ -44,4 +43,5 @@ "standard-version": "latest", | ||
"ts-jest": "latest", | ||
"typescript": "latest" | ||
"typescript": "latest", | ||
"ufo": "latest" | ||
} | ||
} |
@@ -1,8 +0,8 @@ | ||
[![d](https://img.shields.io/npm/dm/@nuxt/h2.svg?style=flat-square)](https://npmjs.com/package/@nuxt/h2) | ||
[![v](https://img.shields.io/npm/v/@nuxt/h2/latest.svg?style=flat-square)](https://npmjs.com/package/@nuxt/h2) | ||
[![b](https://img.shields.io/bundlephobia/min/@nuxt/h2/latest.svg?style=flat-square)](https://bundlephobia.com/result?p=@nuxt/h2) | ||
[![a](https://img.shields.io/github/workflow/status/nuxt-contrib/h2/ci/main?style=flat-square)](https://github.com/nuxt-contrib/h2/actions) | ||
[![c](https://img.shields.io/codecov/c/gh/nuxt-contrib/h2/main?style=flat-square)](https://codecov.io/gh/nuxt-contrib/h2) | ||
[![d](https://img.shields.io/npm/dm/h3.svg?style=flat-square)](https://npmjs.com/package/h3) | ||
[![v](https://img.shields.io/npm/v/h3/latest.svg?style=flat-square)](https://npmjs.com/package/h3) | ||
[![b](https://img.shields.io/bundlephobia/min/h3/latest.svg?style=flat-square)](https://bundlephobia.com/result?p=h3) | ||
[![a](https://img.shields.io/github/workflow/status/nuxt-contrib/h3/ci/main?style=flat-square)](https://github.com/nuxt-contrib/h3/actions) | ||
[![c](https://img.shields.io/codecov/c/gh/nuxt-contrib/h3/main?style=flat-square)](https://codecov.io/gh/nuxt-contrib/h3) | ||
![h2 - Tiny JavaScript Server](.github/banner.svg) | ||
![h3 - Tiny JavaScript Server](.github/banner.svg) | ||
@@ -24,5 +24,5 @@ **What?** | ||
```bash | ||
yarn add @nuxt/h2 | ||
yarn add h3 | ||
# or | ||
npm install @nuxt/h2 | ||
npm install h3 | ||
``` | ||
@@ -35,3 +35,3 @@ | ||
```js | ||
const { createApp } = require('@nuxt/h2') | ||
const { createApp } = require('h3') | ||
const { listen } = require('listhen') | ||
@@ -49,3 +49,3 @@ | ||
const { Server } = require('http') | ||
const { createApp } = require('@nuxt/h2') | ||
const { createApp } = require('h3') | ||
@@ -52,0 +52,0 @@ const app = createApp() |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
Found 1 instance in 1 package
51161
1253
0