New
v3.0.0
This is a major release.
Breaking
- Minimum node v18
- Removes
.redirect('back'), adds.back(fallback_url)@fl0w https://github.com/koajs/koa/pull/1115 - For
.redirect(), don't render redirect values in anchor ref https://github.com/koajs/koa/commit/ff25eb4a7f2392df46481fe86355161067687312 req.originshould display the origin header if it exists, not the current hostname https://github.com/koajs/koa/issues/1008.originnow aligns with theOriginheader as used in CORS..body=<json>should not overwrite type if type already json https://github.com/koajs/koa/issues/1120- Remove special ENOENT support https://github.com/koajs/koa/pull/1861 - this is a big change and will require any file servers to adapt to this change for handling 404s / files not found
- Removes generator deprecation messages. Generators are no longer supported. Koa no longer asserts if generators are used. Set content-length: 0 if body is explicitly set to null @ognjenjevremovic #1528 Remove obsolete createAsyncCtxStorageMiddleware https://github.com/koajs/koa/pull/1817
ctx.thrownow requires a format ofctx.throw(status, error, properties). See: https://www.npmjs.com/package/http-errors
New
- Support custom streams @KristapsR https://github.com/koajs/koa/pull/1825
- Support WHATWG response bodies https://github.com/koajs/koa/pull/1830 @kravorkid
- Use asyncLocalStorage to get current context from app, e.g.:
const ctx = app.currentContext.
Fixes
- Handle responses when socket is no longer writable @titanism @azlond https://github.com/koajs/koa/pull/1593
- fix: Do not response Content-Length if Transfer-Encoding is defined #1562 @charlyzeng
- fix: Set body to 'null' if
ctx.type = 'json'andctx.body = null#1059 @likegun - fix: can not get currentContext in error handler (#1758) (Gxkl <gxkl203@gmail.com>)
- Fix exports.defaults in package.json https://github.com/koajs/koa/pull/1630
- Fix leaky handles in tests https://github.com/koajs/koa/pull/1838
- Fix body null checks https://github.com/koajs/koa/pull/1814
- Fix reformatting redirect URLs https://github.com/koajs/koa/pull/1805 https://github.com/koajs/koa/pull/1804
- Fix passing ctx in error handler https://github.com/koajs/koa/pull/1758
- Avoid redos on host and protocol getter
Refactors
- Replace node query string with URLSearchParams https://github.com/koajs/koa/pull/1828 @kravorkid
Dependencies
- bump type-is@2
- bump http-errors@2
- bump cookies@0.9.1
- bump statuses@2
- bump supertest@7