Socket
Socket
Sign inDemoInstall

h3

Package Overview
Dependencies
Maintainers
1
Versions
98
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

h3 - npm Package Compare versions

Comparing version 0.2.5 to 0.2.6

114

CHANGELOG.md

@@ -5,12 +5,14 @@ # Changelog

### [0.2.5](https://github.com/nuxt-contrib/h3/compare/v0.2.4...v0.2.5) (2021-02-19)
### [0.2.6](https://github.com/unjs/h3/compare/v0.2.5...v0.2.6) (2021-03-27)
### [0.2.4](https://github.com/nuxt-contrib/h3/compare/v0.2.3...v0.2.4) (2021-01-22)
### [0.2.5](https://github.com/unjs/h3/compare/v0.2.4...v0.2.5) (2021-02-19)
### [0.2.4](https://github.com/unjs/h3/compare/v0.2.3...v0.2.4) (2021-01-22)
### Bug Fixes
* always restore req.url for each layer to avoid mutation ([aae5787](https://github.com/nuxt-contrib/h3/commit/aae57876a1bad3972bec86cee385db308ac69764))
* always restore req.url for each layer to avoid mutation ([aae5787](https://github.com/unjs/h3/commit/aae57876a1bad3972bec86cee385db308ac69764))
### [0.2.3](https://github.com/nuxt-contrib/h3/compare/v0.2.2...v0.2.3) (2021-01-20)
### [0.2.3](https://github.com/unjs/h3/compare/v0.2.2...v0.2.3) (2021-01-20)

@@ -20,5 +22,5 @@

* improve internal error handling ([b38d450](https://github.com/nuxt-contrib/h3/commit/b38d450e39101104333f33516d75869cd2427f9d))
* improve internal error handling ([b38d450](https://github.com/unjs/h3/commit/b38d450e39101104333f33516d75869cd2427f9d))
### [0.2.2](https://github.com/nuxt-contrib/h3/compare/v0.2.1...v0.2.2) (2021-01-20)
### [0.2.2](https://github.com/unjs/h3/compare/v0.2.1...v0.2.2) (2021-01-20)

@@ -28,8 +30,8 @@

* capture stacktrace from createError ([1441784](https://github.com/nuxt-contrib/h3/commit/14417846554f81f44ae677bfd609517dcfd3c291))
* handle thrown errors by each layer ([62fd25a](https://github.com/nuxt-contrib/h3/commit/62fd25a572de72a1f555b8f43e5e4798c392b74b))
* capture stacktrace from createError ([1441784](https://github.com/unjs/h3/commit/14417846554f81f44ae677bfd609517dcfd3c291))
* handle thrown errors by each layer ([62fd25a](https://github.com/unjs/h3/commit/62fd25a572de72a1f555b8f43e5e4798c392b74b))
### [0.2.1](https://github.com/nuxt-contrib/h3/compare/v0.2.0...v0.2.1) (2021-01-12)
### [0.2.1](https://github.com/unjs/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)
## [0.2.0](https://github.com/unjs/h3/compare/v0.0.15...v0.2.0) (2020-12-15)

@@ -43,7 +45,7 @@

* `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))
* `useCookie`, `useCookies` and `setCookie` utilities ([088f413](https://github.com/unjs/h3/commit/088f413434a619a9888bfd9d1b189e56a7d00124)), closes [#17](https://github.com/unjs/h3/issues/17)
* appendHeader utility ([84be904](https://github.com/unjs/h3/commit/84be9040e2c52b625a47591e8f5107793da29f72))
* rename useBodyJSON to useBody and unexposed cached value ([d8d39a0](https://github.com/unjs/h3/commit/d8d39a0eefbc22c8d3af8e7dcee5ee8964da07e3))
### [0.0.15](https://github.com/nuxt-contrib/h3/compare/v0.0.14...v0.0.15) (2020-12-12)
### [0.0.15](https://github.com/unjs/h3/compare/v0.0.14...v0.0.15) (2020-12-12)

@@ -53,4 +55,4 @@

* 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))
* add request and response utils ([#15](https://github.com/unjs/h3/issues/15)) ([648e9b9](https://github.com/unjs/h3/commit/648e9b9ceff3a8658a7e3705164d5139e6f95c99))
* custom error handler ([ad3515f](https://github.com/unjs/h3/commit/ad3515f0da8bb37d3f82a6527c459aa86a63e338))

@@ -60,7 +62,7 @@

* 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))
* don't override internal flag ([a5ee318](https://github.com/unjs/h3/commit/a5ee31888101cbe7458d7a63527d0cf07845d2a6))
* hide 404 error ([38fb027](https://github.com/unjs/h3/commit/38fb027bb5a2d3d369f7d3e333edc1342cf32914))
* preserve error message in console ([3002b27](https://github.com/unjs/h3/commit/3002b27aace50cf6d39c289b8500bb92a065fe7a))
### [0.0.14](https://github.com/nuxt-contrib/h3/compare/v0.0.13...v0.0.14) (2020-12-05)
### [0.0.14](https://github.com/unjs/h3/compare/v0.0.13...v0.0.14) (2020-12-05)

@@ -70,6 +72,6 @@

* **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))
* **app:** handle buffer ([09c9c6d](https://github.com/unjs/h3/commit/09c9c6da5bcd00ff49e815cae3c74893d4b4806d))
* **utils:** avoid setting falsy type ([df5e92b](https://github.com/unjs/h3/commit/df5e92b07ca2c096fb078c0deff50b613245c0db))
### [0.0.13](https://github.com/nuxt-contrib/h3/compare/v0.0.12...v0.0.13) (2020-12-05)
### [0.0.13](https://github.com/unjs/h3/compare/v0.0.12...v0.0.13) (2020-12-05)

@@ -79,5 +81,5 @@

* enable debug by default ([010cdfe](https://github.com/nuxt-contrib/h3/commit/010cdfe32ce80b2453489f8839c5f3d946d027a1))
* enable debug by default ([010cdfe](https://github.com/unjs/h3/commit/010cdfe32ce80b2453489f8839c5f3d946d027a1))
### [0.0.12](https://github.com/nuxt-contrib/h3/compare/v0.0.11...v0.0.12) (2020-11-23)
### [0.0.12](https://github.com/unjs/h3/compare/v0.0.11...v0.0.12) (2020-11-23)

@@ -87,3 +89,3 @@

* 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)
* allow chaining use statements ([#9](https://github.com/unjs/h3/issues/9)) ([e30ea79](https://github.com/unjs/h3/commit/e30ea7911ed378866f2c61b0ece3f332e113e821)), closes [#5](https://github.com/unjs/h3/issues/5)

@@ -93,7 +95,7 @@

* 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))
* correctly expose route and middleware types ([#10](https://github.com/unjs/h3/issues/10)) ([bb6cd4c](https://github.com/unjs/h3/commit/bb6cd4c6971fc269d6a313ebc07910898b32f178)), closes [#11](https://github.com/unjs/h3/issues/11) [#11](https://github.com/unjs/h3/issues/11)
* ensure correct url is used when used as a sub-app ([0e4770a](https://github.com/unjs/h3/commit/0e4770af89757c274b1d3e6d7c54b973a7bf9bef))
* mark app._handle as private to avoid sub-app detection ([1439f35](https://github.com/unjs/h3/commit/1439f354a7e9238113f6d8bc7687df8a5fe7bd10))
### [0.0.11](https://github.com/nuxt-contrib/h3/compare/v0.0.10...v0.0.11) (2020-11-21)
### [0.0.11](https://github.com/unjs/h3/compare/v0.0.10...v0.0.11) (2020-11-21)

@@ -103,6 +105,6 @@

* `useAsync` ([236e979](https://github.com/nuxt-contrib/h3/commit/236e97953ac014dffa8977c4bf8cd6f2fa369eb7))
* custom matcher and improved docs ([1c4f9d1](https://github.com/nuxt-contrib/h3/commit/1c4f9d138dde212486d1aa7acb0e2df9a8cb8aca))
* `useAsync` ([236e979](https://github.com/unjs/h3/commit/236e97953ac014dffa8977c4bf8cd6f2fa369eb7))
* custom matcher and improved docs ([1c4f9d1](https://github.com/unjs/h3/commit/1c4f9d138dde212486d1aa7acb0e2df9a8cb8aca))
### [0.0.10](https://github.com/nuxt-contrib/h3/compare/v0.0.9...v0.0.10) (2020-11-20)
### [0.0.10](https://github.com/unjs/h3/compare/v0.0.9...v0.0.10) (2020-11-20)

@@ -112,5 +114,5 @@

* rewrite with much sexier API ([0d3680e](https://github.com/nuxt-contrib/h3/commit/0d3680eacab44d6a40c10b94cfba2036afc571d9))
* rewrite with much sexier API ([0d3680e](https://github.com/unjs/h3/commit/0d3680eacab44d6a40c10b94cfba2036afc571d9))
### [0.0.9](https://github.com/nuxt-contrib/h3/compare/v0.0.8...v0.0.9) (2020-11-20)
### [0.0.9](https://github.com/unjs/h3/compare/v0.0.8...v0.0.9) (2020-11-20)

@@ -120,3 +122,3 @@

* createError ([1a80bd9](https://github.com/nuxt-contrib/h3/commit/1a80bd9432b0585a474d6888e7035636307eead8))
* createError ([1a80bd9](https://github.com/unjs/h3/commit/1a80bd9432b0585a474d6888e7035636307eead8))

@@ -126,5 +128,5 @@

* throw 404 only when writableEnded is not set ([1c42a07](https://github.com/nuxt-contrib/h3/commit/1c42a07e3ecc175c96dff026967298a107314f5e))
* throw 404 only when writableEnded is not set ([1c42a07](https://github.com/unjs/h3/commit/1c42a07e3ecc175c96dff026967298a107314f5e))
### [0.0.8](https://github.com/nuxt-contrib/h3/compare/v0.0.7...v0.0.8) (2020-11-19)
### [0.0.8](https://github.com/unjs/h3/compare/v0.0.7...v0.0.8) (2020-11-19)

@@ -134,7 +136,7 @@

* don't log 404 ([541ede0](https://github.com/nuxt-contrib/h3/commit/541ede03edc6526b953c8a0bb7f31f0dc5fc21d3))
* don't log 404 ([541ede0](https://github.com/unjs/h3/commit/541ede03edc6526b953c8a0bb7f31f0dc5fc21d3))
### [0.0.7](https://github.com/nuxt-contrib/h3/compare/v0.0.6...v0.0.7) (2020-11-19)
### [0.0.7](https://github.com/unjs/h3/compare/v0.0.6...v0.0.7) (2020-11-19)
### [0.0.6](https://github.com/nuxt-contrib/h3/compare/v0.0.5...v0.0.6) (2020-11-19)
### [0.0.6](https://github.com/unjs/h3/compare/v0.0.5...v0.0.6) (2020-11-19)

@@ -144,5 +146,5 @@

* add debug option to app ([b0891cd](https://github.com/nuxt-contrib/h3/commit/b0891cd13d4a7b8ed0fb981ae878185c6728b618))
* add debug option to app ([b0891cd](https://github.com/unjs/h3/commit/b0891cd13d4a7b8ed0fb981ae878185c6728b618))
### [0.0.5](https://github.com/nuxt-contrib/h3/compare/v0.0.4...v0.0.5) (2020-11-19)
### [0.0.5](https://github.com/unjs/h3/compare/v0.0.4...v0.0.5) (2020-11-19)

@@ -152,5 +154,5 @@

* expose unsafeHandle ([f1245f1](https://github.com/nuxt-contrib/h3/commit/f1245f13c1a4ec1f9e1ecb4b0b73c50047ee4d3a))
* expose unsafeHandle ([f1245f1](https://github.com/unjs/h3/commit/f1245f13c1a4ec1f9e1ecb4b0b73c50047ee4d3a))
### [0.0.4](https://github.com/nuxt-contrib/h3/compare/v0.0.3...v0.0.4) (2020-11-19)
### [0.0.4](https://github.com/unjs/h3/compare/v0.0.3...v0.0.4) (2020-11-19)

@@ -160,3 +162,3 @@

* rewrite promisify logic ([a40aa81](https://github.com/nuxt-contrib/h3/commit/a40aa81aa80da3ba418061338bcaa6286357ab67))
* rewrite promisify logic ([a40aa81](https://github.com/unjs/h3/commit/a40aa81aa80da3ba418061338bcaa6286357ab67))

@@ -166,6 +168,6 @@

* 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))
* keep top level trailing slash ([2fb92ef](https://github.com/unjs/h3/commit/2fb92efdf462f3c4098af3cac6594599839f7cde))
* stop middleware when writableEnded flag is set ([d87d8e5](https://github.com/unjs/h3/commit/d87d8e5f7a426409565d1a008b8231c793ec61ef))
### [0.0.3](https://github.com/nuxt-contrib/h3/compare/v0.0.2...v0.0.3) (2020-11-19)
### [0.0.3](https://github.com/unjs/h3/compare/v0.0.2...v0.0.3) (2020-11-19)

@@ -175,5 +177,5 @@

* improve error util ([5504f4e](https://github.com/nuxt-contrib/h3/commit/5504f4e53dfb19cceb6580b00077f8c80d0b5dc5))
* improve error util ([5504f4e](https://github.com/unjs/h3/commit/5504f4e53dfb19cceb6580b00077f8c80d0b5dc5))
### [0.0.2](https://github.com/nuxt-contrib/h3/compare/v0.0.1...v0.0.2) (2020-11-19)
### [0.0.2](https://github.com/unjs/h3/compare/v0.0.1...v0.0.2) (2020-11-19)

@@ -183,3 +185,3 @@

* remove dependency on process.env ([eb018f5](https://github.com/nuxt-contrib/h3/commit/eb018f5e23a5f797a4b5d24fdbfe591994c39aef))
* remove dependency on process.env ([eb018f5](https://github.com/unjs/h3/commit/eb018f5e23a5f797a4b5d24fdbfe591994c39aef))

@@ -191,4 +193,4 @@ ### 0.0.1 (2020-11-18)

* 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))
* de-default loazy handles ([0cb8c0c](https://github.com/unjs/h3/commit/0cb8c0c74647278806a53f7920f8678bb47749e5))
* update docs and caller utility ([0ef0020](https://github.com/unjs/h3/commit/0ef0020da1931b8c08344008253703b91b318559))

@@ -198,3 +200,3 @@

* **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))
* **app:** handle returning promise ([2169f92](https://github.com/unjs/h3/commit/2169f92142d2e92e143913fff945628f17203779))
* **writable:** set writableEnded and writableFinished ([7058fdc](https://github.com/unjs/h3/commit/7058fdcf38a31edd1ce2afe4b05eb0b050adea78))

@@ -99,3 +99,3 @@ import { IncomingMessage, ServerResponse } from 'http';

/**
* Reads request body and try to safely parse using {@link https://github.com/nuxt-contrib/destr destr}
* Reads request body and try to safely parse using {@link https://github.com/unjs/destr destr}
* @param req {IncomingMessage} An IncomingMessage object is created by

@@ -102,0 +102,0 @@ * <a href="https://nodejs.org/api/http.html#http_class_http_server">http.Server</a>

{
"name": "h3",
"version": "0.2.5",
"version": "0.2.6",
"description": "Tiny JavaScript Server",
"repository": "nuxt-contrib/h3",
"repository": "unjs/h3",
"license": "MIT",

@@ -25,2 +25,3 @@ "sideEffects": false,

"@types/express": "latest",
"@types/jest": "latest",
"@types/node": "latest",

@@ -27,0 +28,0 @@ "@types/supertest": "latest",

[![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)
[![a](https://img.shields.io/github/workflow/status/unjs/h3/ci/main?style=flat-square)](https://github.com/unjs/h3/actions)
[![c](https://img.shields.io/codecov/c/gh/unjs/h3/main?style=flat-square)](https://codecov.io/gh/unjs/h3)
![h3 - Tiny JavaScript Server](.github/banner.svg)
> H3 is a minimal h(ttp) framework built for high performance and portability
**What?**
<!-- ![h3 - Tiny JavaScript Server](.github/banner.svg) -->
- Works perfectly with Serverless, Workers and NodeJS
- Compatible with connect/express middleware
- Tree-shakable and zero-dependency
- Promise and `aync/await` support
- Lazy loading
- Quick prefix router
- Custom route matcher
**Features**
> See [un](https://github.com/nuxt-contrib/un) for workers support
✔️ **Portable:** Works perfectly in Serverless, Workers, and Node.js
✔️ **Compatible:** Support connect/express middleware
✔️ **Minimal:** Small, tree-shakable and zero-dependency
✔️ **Modern:** Native promise support
✔️**Extendable:** Ships with a set of composable utilities but can be extended
## Install
```bash
# Using npm
npm install h3
# Using yarn
yarn add h3
# or
npm install h3
```

@@ -31,76 +35,68 @@

**Using [listhen](https://github.com/nuxt-contrib/listhen):**
```ts
import { createServer } from 'http'
import { createApp } from 'h3'
```js
const { createApp } = require('h3')
const { listen } = require('listhen')
const app = createApp()
app.use('/', () => 'Hello world!')
app.useAsync('/', () => 'Hello world!')
listhen(app)
listen(app)
```
**Using plain node:**
**Tip:** you may try [listhen](https://github.com/unjs/listhen) for a more elegant and advanced listener.
## Examples
```js
const { Server } = require('http')
const { createApp } = require('h3')
const app = createApp()
// Handle can directly return object or Promise<object> for JSON response
app.use('/api', (req) => ({ url: req.url }))
app.useAsync('/api', (req) => ({ url: req.url }))
// You can have better matching other than quick prefix match
app.use('/odd', () => 'Is odd!', { match: url => url.substr(1) % 2 })
// We can have better matching other than quick prefix match
app.useAsync('/odd', () => 'Is odd!', { match: url => url.substr(1) % 2 })
// Handle can directly return string for HTML response
app.use(() => '<h1>Hello world!</h1>')
app.useAsync(() => '<h1>Hello world!</h1>')
// You can chain calls to .use()
app.use('/1', () => '<h1>Hello world!</h1>').use('/2', () => '<h1>Goodbye!</h1>')
// We can chain calls to .use()
app.useAsync('/1', () => '<h1>Hello world!</h1>')
.useAsync('/2', () => '<h1>Goodbye!</h1>')
// If handle is already async, using useAsync to avoid unnecessary promisify wrapper
// (Shortcut to pass { promisify: false })
// app.useAsync(async () => {})
// Promisify middleware before register: (supporting (req, res, next) format)
// app.use(async () => {})
// Lazy loading routes using { lazy: true }
// Lazy loaded routes using { lazy: true }
// app.use('/big', () => import('./big'), { lazy: true })
const port = process.env.PORT || 3000
const server = new Server(app)
server.listen(port, () => {
console.log(`Listening on: http://localhost:${port}`)
})
```
## Technical
## Utilities
There are two vital parts that make it working: Stack Runner (`App`), and `promisifyHandle`.
Instead of adding helpers to `req` and `res`, h3 exposes them as composable utilities.
### App
- `useRawBody(req, encoding?)`
- `useBody(req)`
- `useCookies(req)`
- `useCookie(req, name)`
- `setCookie(req, name, value, opts?)`
- `useQuery(req)`
- `send(res, data, type?)`
- `sendRedirect(res, location, code=302)`
- `appendHeader(res, name, value)`
- `createError({ statusCode, statusMessage, data? }`
- `sendError(res, error, debug?)`
App is basically a http server handle with `req, res` and attached utilities that runs a stack
of middleware/handles in parallel. It will stop when the `writableEnded` flag is set on a response
(which means that `res.end` has been called) and throw a 404 if `writableEnded` flag has not been set by the end.
## How it works?
Additionally the app has a quick prefix matcher and will automatically call `res.end` if any stack layers return a value.
Using `createApp`, it returns a standard `(req, res)` handler function and internally an array called middleware stack. `useAsync()` and `use()` methods are helpers to add an item to this internal stack.
### `promisifyHandle`
When a request comes, each stack item that matches the route will be called and resolved until [`res.writableEnded`](https://nodejs.org/api/http.html#http_response_writableended) flag is set, which means the response is sent. If `writableEnded` is not set after all middleware, a `404` error will be thrown. And if one of the stack items resolves to a value, it will be serialized and sent as response as a shorthand method to sending responses.
Converts a classic middleware (`req, res, next?`) into a promisified version ready to use with App
For maximum compatibility with connect/express middleware (`req, res, next?` signature), when using `use` instead of `useAsync`, it converts classic middleware into a promisified version ready to use with stack runner:
- If middleware has 3rd next/callback param, promise will `resolve/reject` when called
- If middleware returns a promise, it will be **chained** to main promise
- If middleware returns a promise, it will be **chained** to the main promise
- If calling middleware throws an immediate error, promise will be rejected
- On `close` and `error` events of res, promise will `resolve/reject` (to ensure if middleware simply calls `res.end`)
When calling `app.use`, middleware will be automatically promisified.
If you are already making an async aware middleware, you can use `app.useAsync`
## License
MIT
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc