dependabot[bot] d5081a1520 build(deps): bump type-is from 1.6.18 to 2.0.1 (#1866)
Bumps [type-is](https://github.com/jshttp/type-is) from 1.6.18 to 2.0.1.
<details>
<summary>Release notes</summary>
<p><em>Sourced from <a
href="https://github.com/jshttp/type-is/releases">type-is's
releases</a>.</em></p>
<blockquote>
<h2>2.0.1</h2>
<h2>What's Changed</h2>
<ul>
<li>Refactor normalizeType function to simplify return statement by <a
href="https://github.com/Ayoub-Mabrouk"><code>@​Ayoub-Mabrouk</code></a>
in <a
href="https://redirect.github.com/jshttp/type-is/pull/61">jshttp/type-is#61</a></li>
<li>Refactor tryNormalizeType function for cleaner code by <a
href="https://github.com/Ayoub-Mabrouk"><code>@​Ayoub-Mabrouk</code></a>
in <a
href="https://redirect.github.com/jshttp/type-is/pull/59">jshttp/type-is#59</a></li>
<li>Replace deprecated String.prototype.substr() by <a
href="https://github.com/CommanderRoot"><code>@​CommanderRoot</code></a>
in <a
href="https://redirect.github.com/jshttp/type-is/pull/50">jshttp/type-is#50</a></li>
<li>Optimize argument handling in typeofrequest function by <a
href="https://github.com/Ayoub-Mabrouk"><code>@​Ayoub-Mabrouk</code></a>
in <a
href="https://redirect.github.com/jshttp/type-is/pull/60">jshttp/type-is#60</a></li>
<li>Release 2.0.1 by <a
href="https://github.com/UlisesGascon"><code>@​UlisesGascon</code></a>
in <a
href="https://redirect.github.com/jshttp/type-is/pull/64">jshttp/type-is#64</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/Ayoub-Mabrouk"><code>@​Ayoub-Mabrouk</code></a>
made their first contribution in <a
href="https://redirect.github.com/jshttp/type-is/pull/61">jshttp/type-is#61</a></li>
<li><a
href="https://github.com/CommanderRoot"><code>@​CommanderRoot</code></a>
made their first contribution in <a
href="https://redirect.github.com/jshttp/type-is/pull/50">jshttp/type-is#50</a></li>
<li><a
href="https://github.com/UlisesGascon"><code>@​UlisesGascon</code></a>
made their first contribution in <a
href="https://redirect.github.com/jshttp/type-is/pull/64">jshttp/type-is#64</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/jshttp/type-is/compare/2.0.0...2.0.1">https://github.com/jshttp/type-is/compare/2.0.0...2.0.1</a></p>
<h2>2.0.0</h2>
<h2>What's Changed</h2>
<ul>
<li>README changes by <a
href="https://github.com/Yash-Singh1"><code>@​Yash-Singh1</code></a> in
<a
href="https://redirect.github.com/jshttp/type-is/pull/48">jshttp/type-is#48</a></li>
<li>add OSSF scorecard pipeline by <a
href="https://github.com/carpasse"><code>@​carpasse</code></a> in <a
href="https://redirect.github.com/jshttp/type-is/pull/55">jshttp/type-is#55</a></li>
<li>Fix ci pipeline by <a
href="https://github.com/carpasse"><code>@​carpasse</code></a> in <a
href="https://redirect.github.com/jshttp/type-is/pull/54">jshttp/type-is#54</a></li>
<li>2.x Staging PR by <a
href="https://github.com/wesleytodd"><code>@​wesleytodd</code></a> in <a
href="https://redirect.github.com/jshttp/type-is/pull/57">jshttp/type-is#57</a></li>
</ul>
<h2>New Contributors</h2>
<ul>
<li><a
href="https://github.com/Yash-Singh1"><code>@​Yash-Singh1</code></a>
made their first contribution in <a
href="https://redirect.github.com/jshttp/type-is/pull/48">jshttp/type-is#48</a></li>
<li><a href="https://github.com/carpasse"><code>@​carpasse</code></a>
made their first contribution in <a
href="https://redirect.github.com/jshttp/type-is/pull/55">jshttp/type-is#55</a></li>
</ul>
<p><strong>Full Changelog</strong>: <a
href="https://github.com/jshttp/type-is/compare/1.6.18...2.0.0">https://github.com/jshttp/type-is/compare/1.6.18...2.0.0</a></p>
</blockquote>
</details>
<details>
<summary>Changelog</summary>
<p><em>Sourced from <a
href="https://github.com/jshttp/type-is/blob/master/HISTORY.md">type-is's
changelog</a>.</em></p>
<blockquote>
<h1>2.0.1 / 2025-03-27</h1>
<h1>2.0.0 / 2024-08-31</h1>
<ul>
<li>Drop node &lt;18</li>
<li>Use <code>content-type@^1.0.5</code> and
<code>media-typer@^1.0.0</code> for type validation
<ul>
<li>No behavior changes, upgrades <code>media-typer</code></li>
</ul>
</li>
<li>deps: mime-types@^3.0.0
<ul>
<li>Add <code>application/toml</code> with extension
<code>.toml</code></li>
<li>Add <code>application/ubjson</code> with extension
<code>.ubj</code></li>
<li>Add <code>application/x-keepass2</code> with extension
<code>.kdbx</code></li>
<li>Add deprecated iWorks mime types and extensions</li>
<li>Add extension <code>.amr</code> to <code>audio/amr</code></li>
<li>Add extension <code>.cjs</code> to
<code>application/node</code></li>
<li>Add extension <code>.dbf</code> to
<code>application/vnd.dbf</code></li>
<li>Add extension <code>.m4s</code> to
<code>video/iso.segment</code></li>
<li>Add extension <code>.mvt</code> to
<code>application/vnd.mapbox-vector-tile</code></li>
<li>Add extension <code>.mxmf</code> to
<code>audio/mobile-xmf</code></li>
<li>Add extension <code>.opus</code> to <code>audio/ogg</code></li>
<li>Add extension <code>.rar</code> to
<code>application/vnd.rar</code></li>
<li>Add extension <code>.td</code> to
<code>application/urc-targetdesc+xml</code></li>
<li>Add extension <code>.trig</code> to
<code>application/trig</code></li>
<li>Add extensions from IANA for <code>application/*+xml</code>
types</li>
<li>Add <code>image/avif</code> with extension <code>.avif</code></li>
<li>Add <code>image/ktx2</code> with extension <code>.ktx2</code></li>
<li>Add <code>image/vnd.ms-dds</code> with extension
<code>.dds</code></li>
<li>Add new upstream MIME types</li>
<li>Fix extension of <code>application/vnd.apple.keynote</code> to be
<code>.key</code></li>
<li>Remove ambigious extensions from IANA for
<code>application/*+xml</code> types</li>
<li>Update primary extension to <code>.es</code> for
<code>application/ecmascript</code></li>
</ul>
</li>
</ul>
</blockquote>
</details>
<details>
<summary>Commits</summary>
<ul>
<li><a
href="4a16e0850e"><code>4a16e08</code></a>
2.0.1 (<a
href="https://redirect.github.com/jshttp/type-is/issues/64">#64</a>)</li>
<li><a
href="e45c6afedc"><code>e45c6af</code></a>
chore: refactor <code>typeofrequest</code> function (<a
href="https://redirect.github.com/jshttp/type-is/issues/60">#60</a>)</li>
<li><a
href="b4e746dcbc"><code>b4e746d</code></a>
chore: refactor to replace deprecated String method (<a
href="https://redirect.github.com/jshttp/type-is/issues/50">#50</a>)</li>
<li><a
href="a00e748eeb"><code>a00e748</code></a>
chore: refactor <code>tryNormalizeType</code> function (<a
href="https://redirect.github.com/jshttp/type-is/issues/59">#59</a>)</li>
<li><a
href="5ecc1414eb"><code>5ecc141</code></a>
chore: refactor <code>normalizeType</code> function (<a
href="https://redirect.github.com/jshttp/type-is/issues/61">#61</a>)</li>
<li><a
href="0d79e2d0c5"><code>0d79e2d</code></a>
2.0.0</li>
<li><a
href="d8a2552c02"><code>d8a2552</code></a>
fix(deps): accept minors of media-typer</li>
<li><a
href="e5dc464bc8"><code>e5dc464</code></a>
fix(deps): accept minors of media-typer</li>
<li><a
href="ed1cc660b3"><code>ed1cc66</code></a>
Use content-type and media-typer for type validation</li>
<li><a
href="3700a79ebc"><code>3700a79</code></a>
fix(deps): replace media-typer with content-type</li>
<li>Additional commits viewable in <a
href="https://github.com/jshttp/type-is/compare/1.6.18...2.0.1">compare
view</a></li>
</ul>
</details>
<details>
<summary>Maintainer changes</summary>
<p>This version was pushed to npm by <a
href="https://www.npmjs.com/~ulisesgascon">ulisesgascon</a>, a new
releaser for type-is since your current version.</p>
</details>
<br />


[![Dependabot compatibility
score](https://dependabot-badges.githubapp.com/badges/compatibility_score?dependency-name=type-is&package-manager=npm_and_yarn&previous-version=1.6.18&new-version=2.0.1)](https://docs.github.com/en/github/managing-security-vulnerabilities/about-dependabot-security-updates#about-compatibility-scores)

Dependabot will resolve any conflicts with this PR as long as you don't
alter it yourself. You can also trigger a rebase manually by commenting
`@dependabot rebase`.

[//]: # (dependabot-automerge-start)
[//]: # (dependabot-automerge-end)

---

<details>
<summary>Dependabot commands and options</summary>
<br />

You can trigger Dependabot actions by commenting on this PR:
- `@dependabot rebase` will rebase this PR
- `@dependabot recreate` will recreate this PR, overwriting any edits
that have been made to it
- `@dependabot merge` will merge this PR after your CI passes on it
- `@dependabot squash and merge` will squash and merge this PR after
your CI passes on it
- `@dependabot cancel merge` will cancel a previously requested merge
and block automerging
- `@dependabot reopen` will reopen this PR if it is closed
- `@dependabot close` will close this PR and stop Dependabot recreating
it. You can achieve the same result by closing it manually
- `@dependabot show <dependency name> ignore conditions` will show all
of the ignore conditions of the specified dependency
- `@dependabot ignore this major version` will close this PR and stop
Dependabot creating any more for this major version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this minor version` will close this PR and stop
Dependabot creating any more for this minor version (unless you reopen
the PR or upgrade to it yourself)
- `@dependabot ignore this dependency` will close this PR and stop
Dependabot creating any more for this dependency (unless you reopen the
PR or upgrade to it yourself)


</details>

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2025-04-02 21:25:54 -07:00
2025-03-16 21:39:44 -07:00
2025-03-16 21:30:24 -07:00
2025-03-21 22:42:08 -07:00
2015-10-13 09:23:57 +02:00
2020-06-21 22:26:48 +08:00
2023-11-08 23:05:20 +08:00
2016-03-12 14:22:16 -08:00
2019-01-07 16:41:45 +08:00

Koa middleware framework for nodejs

gitter NPM version build status Test coverage OpenCollective Backers OpenCollective Sponsors PR's Welcome

Expressive HTTP middleware framework for node.js to make web applications and APIs more enjoyable to write. Koa's middleware stack flows in a stack-like manner, allowing you to perform actions downstream then filter and manipulate the response upstream.

Only methods that are common to nearly all HTTP servers are integrated directly into Koa's small ~570 SLOC codebase. This includes things like content negotiation, normalization of node inconsistencies, redirection, and a few others.

Koa is not bundled with any middleware.

Installation

Koa requires node v18.0.0 or higher for ES2015 and async function support.

$ npm install koa

Hello Koa

const Koa = require('koa');
const app = new Koa();

// response
app.use(ctx => {
  ctx.body = 'Hello Koa';
});

app.listen(3000);

Getting started

  • Kick-Off-Koa - An intro to Koa via a set of self-guided workshops.
  • Guide - Go straight to the docs.

Middleware

Koa is a middleware framework that can take two different kinds of functions as middleware:

  • async function
  • common function

Here is an example of logger middleware with each of the different functions:

async functions (node v7.6+)

app.use(async (ctx, next) => {
  const start = Date.now();
  await next();
  const ms = Date.now() - start;
  console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
});

Common function

// Middleware normally takes two parameters (ctx, next), ctx is the context for one request,
// next is a function that is invoked to execute the downstream middleware. It returns a Promise with a then function for running code after completion.

app.use((ctx, next) => {
  const start = Date.now();
  return next().then(() => {
    const ms = Date.now() - start;
    console.log(`${ctx.method} ${ctx.url} - ${ms}ms`);
  });
});

Koa v1.x Middleware Signature

The middleware signature changed between v1.x and v2.x. The older signature is deprecated.

Old signature middleware support will be removed in v3

Please see the Migration Guide for more information on upgrading from v1.x and using v1.x middleware with v2.x.

Context, Request and Response

Each middleware receives a Koa Context object that encapsulates an incoming http message and the corresponding response to that message. ctx is often used as the parameter name for the context object.

app.use(async (ctx, next) => { await next(); });

Koa provides a Request object as the request property of the Context.
Koa's Request object provides helpful methods for working with http requests which delegate to an IncomingMessage from the node http module.

Here is an example of checking that a requesting client supports xml.

app.use(async (ctx, next) => {
  ctx.assert(ctx.request.accepts('xml'), 406);
  // equivalent to:
  // if (!ctx.request.accepts('xml')) ctx.throw(406);
  await next();
});

Koa provides a Response object as the response property of the Context.
Koa's Response object provides helpful methods for working with http responses which delegate to a ServerResponse .

Koa's pattern of delegating to Node's request and response objects rather than extending them provides a cleaner interface and reduces conflicts between different middleware and with Node itself as well as providing better support for stream handling. The IncomingMessage can still be directly accessed as the req property on the Context and ServerResponse can be directly accessed as the res property on the Context.

Here is an example using Koa's Response object to stream a file as the response body.

app.use(async (ctx, next) => {
  await next();
  ctx.response.type = 'xml';
  ctx.response.body = fs.createReadStream('really_large.xml');
});

The Context object also provides shortcuts for methods on its request and response. In the prior examples, ctx.type can be used instead of ctx.response.type and ctx.accepts can be used instead of ctx.request.accepts.

For more information on Request, Response and Context, see the Request API Reference, Response API Reference and Context API Reference.

Koa Application

The object created when executing new Koa() is known as the Koa application object.

The application object is Koa's interface with node's http server and handles the registration of middleware, dispatching to the middleware from http, default error handling, as well as configuration of the context, request and response objects.

Learn more about the application object in the Application API Reference.

Documentation

Troubleshooting

Check the Troubleshooting Guide or Debugging Koa in the general Koa guide.

Running tests

$ npm test

Reporting vulnerabilities

To report a security vulnerability, please do not open an issue, as this notifies attackers of the vulnerability. Instead, please email dead_horse, jonathanong, and niftylettuce to disclose.

Authors

See AUTHORS.

Community

Job Board

Looking for a career upgrade?

Backers

Support us with a monthly donation and help us continue our activities.

Sponsors

Become a sponsor and get your logo on our README on Github with a link to your site.

License

MIT

Description
No description provided
Readme MIT 3.9 MiB
Languages
JavaScript 100%