Skip to content

Commit

Permalink
feat: refactor with typescript
Browse files Browse the repository at this point in the history
  • Loading branch information
fengmk2 committed May 31, 2023
1 parent 3948685 commit 6a28f83
Show file tree
Hide file tree
Showing 80 changed files with 261 additions and 546 deletions.
4 changes: 0 additions & 4 deletions .codecov.yml

This file was deleted.

16 changes: 0 additions & 16 deletions .editorconfig

This file was deleted.

6 changes: 6 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": [
"eslint-config-egg/typescript",
"eslint-config-egg/lib/rules/enforce-node-prefix"
]
}
1 change: 0 additions & 1 deletion .eslintrc.yml

This file was deleted.

87 changes: 2 additions & 85 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

@eggjs/koa is forked from [Koa v2.x](https://github.com/koajs/koa/tree/v2.x) for LTS and drop Node.js < 16.13.0 support.

<img src="/docs/logo.png" alt="Koa middleware framework for nodejs"/>
<img height="240px" src="/docs/logo.png" alt="Koa middleware framework for nodejs"/>

[![NPM version](https://img.shields.io/npm/v/@eggjs/koa.svg?style=flat-square)](https://npmjs.org/package/@eggjs/koa)
[![NPM quality](http://npm.packagequality.com/shield/@eggjs/koa.svg?style=flat-square)](http://packagequality.com/#?package=@eggjs/koa)
[![NPM download](https://img.shields.io/npm/dm/@eggjs/koa.svg?style=flat-square)](https://npmjs.org/package/@eggjs/koa)
[![FOSSA Status](https://app.fossa.com/api/projects/git%2Bgithub.com%2Feggjs%2Fkoa.svg?type=shield)](https://app.fossa.com/projects/git%2Bgithub.com%2Feggjs%2Fkoa?ref=badge_shield)
[![Continuous Integration](https://github.com/eggjs/koa/workflows/Continuous%20integration/badge.svg)](https://github.com/eggjs/koa/actions?query=branch%3Amaster)
[![Node.js CI](https://github.com/eggjs/koa/actions/workflows/node.js.yml/badge.svg?branch=master)](https://github.com/eggjs/koa/actions/workflows/node.js.yml)
[![Test coverage](https://img.shields.io/codecov/c/github/eggjs/koa.svg?style=flat-square)](https://codecov.io/gh/eggjs/koa)
[![Known Vulnerabilities](https://snyk.io/test/npm/@eggjs/koa/badge.svg?style=flat-square)](https://snyk.io/test/npm/@eggjs/koa)

Expand Down Expand Up @@ -186,93 +186,10 @@ See [AUTHORS](AUTHORS).

## Community

- [Badgeboard](https://koajs.github.io/badgeboard) and list of official modules
- [Examples](https://github.com/koajs/examples)
- [Middleware](https://github.com/koajs/koa/wiki) list
- [Wiki](https://github.com/koajs/koa/wiki)
- [Reddit Community](https://www.reddit.com/r/koajs)
- [Mailing list](https://groups.google.com/forum/#!forum/koajs)
- [中文文档 v1.x](https://github.com/guo-yu/koa-guide)
- [中文文档 v2.x](https://github.com/demopark/koa-docs-Zh-CN)
- __[#koajs]__ on freenode

## Job Board

Looking for a career upgrade?

<a href="https://astro.netlify.com/automattic"><img src="https://astro.netlify.com/static/automattic.png"></a>
<a href="https://astro.netlify.com/segment"><img src="https://astro.netlify.com/static/segment.png"></a>
<a href="https://astro.netlify.com/auth0"><img src="https://astro.netlify.com/static/auth0.png"/></a>

## Backers

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

<a href="https://opencollective.com/koajs/backer/0/website" target="_blank"><img src="https://opencollective.com/koajs/backer/0/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/1/website" target="_blank"><img src="https://opencollective.com/koajs/backer/1/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/2/website" target="_blank"><img src="https://opencollective.com/koajs/backer/2/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/3/website" target="_blank"><img src="https://opencollective.com/koajs/backer/3/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/4/website" target="_blank"><img src="https://opencollective.com/koajs/backer/4/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/5/website" target="_blank"><img src="https://opencollective.com/koajs/backer/5/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/6/website" target="_blank"><img src="https://opencollective.com/koajs/backer/6/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/7/website" target="_blank"><img src="https://opencollective.com/koajs/backer/7/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/8/website" target="_blank"><img src="https://opencollective.com/koajs/backer/8/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/9/website" target="_blank"><img src="https://opencollective.com/koajs/backer/9/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/10/website" target="_blank"><img src="https://opencollective.com/koajs/backer/10/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/11/website" target="_blank"><img src="https://opencollective.com/koajs/backer/11/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/12/website" target="_blank"><img src="https://opencollective.com/koajs/backer/12/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/13/website" target="_blank"><img src="https://opencollective.com/koajs/backer/13/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/14/website" target="_blank"><img src="https://opencollective.com/koajs/backer/14/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/15/website" target="_blank"><img src="https://opencollective.com/koajs/backer/15/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/16/website" target="_blank"><img src="https://opencollective.com/koajs/backer/16/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/17/website" target="_blank"><img src="https://opencollective.com/koajs/backer/17/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/18/website" target="_blank"><img src="https://opencollective.com/koajs/backer/18/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/19/website" target="_blank"><img src="https://opencollective.com/koajs/backer/19/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/20/website" target="_blank"><img src="https://opencollective.com/koajs/backer/20/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/21/website" target="_blank"><img src="https://opencollective.com/koajs/backer/21/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/22/website" target="_blank"><img src="https://opencollective.com/koajs/backer/22/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/23/website" target="_blank"><img src="https://opencollective.com/koajs/backer/23/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/24/website" target="_blank"><img src="https://opencollective.com/koajs/backer/24/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/25/website" target="_blank"><img src="https://opencollective.com/koajs/backer/25/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/26/website" target="_blank"><img src="https://opencollective.com/koajs/backer/26/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/27/website" target="_blank"><img src="https://opencollective.com/koajs/backer/27/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/28/website" target="_blank"><img src="https://opencollective.com/koajs/backer/28/avatar.svg"></a>
<a href="https://opencollective.com/koajs/backer/29/website" target="_blank"><img src="https://opencollective.com/koajs/backer/29/avatar.svg"></a>

## Sponsors

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

<a href="https://opencollective.com/koajs/sponsor/0/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/0/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/1/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/1/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/2/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/2/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/3/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/3/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/4/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/4/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/5/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/5/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/6/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/6/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/7/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/7/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/8/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/8/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/9/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/9/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/10/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/10/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/11/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/11/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/12/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/12/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/13/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/13/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/14/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/14/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/15/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/15/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/16/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/16/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/17/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/17/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/18/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/18/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/19/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/19/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/20/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/20/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/21/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/21/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/22/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/22/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/23/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/23/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/24/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/24/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/25/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/25/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/26/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/26/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/27/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/27/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/28/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/28/avatar.svg"></a>
<a href="https://opencollective.com/koajs/sponsor/29/website" target="_blank"><img src="https://opencollective.com/koajs/sponsor/29/avatar.svg"></a>

# License

Expand Down
12 changes: 0 additions & 12 deletions __tests__/.eslintrc.yml

This file was deleted.

43 changes: 0 additions & 43 deletions __tests__/load-with-esm.js

This file was deleted.

45 changes: 18 additions & 27 deletions lib/application.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,20 @@

'use strict';

/**
* Module dependencies.
*/

const debug = require('node:util').debuglog('koa:application');

Check failure on line 1 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

Require statement not part of import statement

Check failure on line 1 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Require statement not part of import statement

Check failure on line 1 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Require statement not part of import statement

Check failure on line 1 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16.13.0)

Require statement not part of import statement
const Emitter = require('node:events');

Check failure on line 2 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

Require statement not part of import statement

Check failure on line 2 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Require statement not part of import statement

Check failure on line 2 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Require statement not part of import statement

Check failure on line 2 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16.13.0)

Require statement not part of import statement
const util = require('node:util');

Check failure on line 3 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

Require statement not part of import statement

Check failure on line 3 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Require statement not part of import statement

Check failure on line 3 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Require statement not part of import statement

Check failure on line 3 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16.13.0)

Require statement not part of import statement
const Stream = require('node:stream');

Check failure on line 4 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

Require statement not part of import statement

Check failure on line 4 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Require statement not part of import statement

Check failure on line 4 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Require statement not part of import statement

Check failure on line 4 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16.13.0)

Require statement not part of import statement
const http = require('node:http');

Check failure on line 5 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

Require statement not part of import statement

Check failure on line 5 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Require statement not part of import statement

Check failure on line 5 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Require statement not part of import statement

Check failure on line 5 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16.13.0)

Require statement not part of import statement
const { AsyncLocalStorage } = require('node:async_hooks');

Check failure on line 6 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

Require statement not part of import statement

Check failure on line 6 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Require statement not part of import statement

Check failure on line 6 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Require statement not part of import statement

Check failure on line 6 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16.13.0)

Require statement not part of import statement
const isGeneratorFunction = require('is-generator-function');

Check failure on line 7 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

Require statement not part of import statement

Check failure on line 7 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Require statement not part of import statement

Check failure on line 7 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Require statement not part of import statement

Check failure on line 7 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16.13.0)

Require statement not part of import statement
const debug = require('debug')('koa:application');
const onFinished = require('on-finished');

Check failure on line 8 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

Require statement not part of import statement

Check failure on line 8 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Require statement not part of import statement

Check failure on line 8 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Require statement not part of import statement

Check failure on line 8 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16.13.0)

Require statement not part of import statement
const assert = require('assert');
const response = require('./response');
const compose = require('koa-compose');
const context = require('./context');
const request = require('./request');
const statuses = require('statuses');

Check failure on line 9 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

Require statement not part of import statement

Check failure on line 9 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Require statement not part of import statement

Check failure on line 9 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Require statement not part of import statement

Check failure on line 9 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16.13.0)

Require statement not part of import statement
const Emitter = require('events');
const util = require('util');
const Stream = require('stream');
const http = require('http');
const compose = require('koa-compose');

Check failure on line 10 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16)

Require statement not part of import statement

Check failure on line 10 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 18)

Require statement not part of import statement

Check failure on line 10 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 20)

Require statement not part of import statement

Check failure on line 10 in lib/application.js

View workflow job for this annotation

GitHub Actions / Node.js / Test (ubuntu-latest, 16.13.0)

Require statement not part of import statement
const only = require('only');
const convert = require('koa-convert');
const deprecate = require('depd')('koa');
const { HttpError } = require('http-errors');
const response = require('./response');
const context = require('./context');
const request = require('./request');

/**
* Expose `Application` class.
Expand Down Expand Up @@ -66,8 +59,6 @@ module.exports = class Application extends Emitter {
this[util.inspect.custom] = this.inspect;
}
if (options.asyncLocalStorage) {
const { AsyncLocalStorage } = require('async_hooks');
assert(AsyncLocalStorage, 'Requires node 12.17.0 or higher to enable asyncLocalStorage');
this.ctxStorage = new AsyncLocalStorage();
}
}
Expand Down Expand Up @@ -100,7 +91,7 @@ module.exports = class Application extends Emitter {
return only(this, [
'subdomainOffset',
'proxy',
'env'
'env',
]);
}

Expand Down Expand Up @@ -156,7 +147,7 @@ module.exports = class Application extends Emitter {
if (!this.ctxStorage) {
return this.handleRequest(ctx, fn);
}
return this.ctxStorage.run(ctx, async() => {
return this.ctxStorage.run(ctx, async () => {
return await this.handleRequest(ctx, fn);
});
};
Expand Down Expand Up @@ -223,7 +214,7 @@ module.exports = class Application extends Emitter {
err instanceof Error;
if (!isNativeError) throw new TypeError(util.format('non-error thrown: %j', err));

if (404 === err.status || err.expose) return;
if (err.status === 404 || err.expose) return;
if (this.silent) return;

const msg = err.stack || err.toString();
Expand All @@ -242,7 +233,7 @@ module.exports = class Application extends Emitter {
createAsyncCtxStorageMiddleware() {
const app = this;
return async function asyncCtxStorage(ctx, next) {
await app.ctxStorage.run(ctx, async() => {
await app.ctxStorage.run(ctx, async () => {
return await next();
});
};
Expand All @@ -255,7 +246,7 @@ module.exports = class Application extends Emitter {

function respond(ctx) {
// allow bypassing koa
if (false === ctx.respond) return;
if (ctx.respond === false) return;

if (!ctx.writable) return;

Expand All @@ -270,7 +261,7 @@ function respond(ctx) {
return res.end();
}

if ('HEAD' === ctx.method) {
if (ctx.method === 'HEAD') {
if (!res.headersSent && !ctx.response.has('Content-Length')) {
const { length } = ctx.response;
if (Number.isInteger(length)) ctx.length = length;
Expand All @@ -279,7 +270,7 @@ function respond(ctx) {
}

// status body
if (null == body) {
if (body == null) {
if (ctx.response._explicitNullBody) {
ctx.response.remove('Content-Type');
ctx.response.remove('Transfer-Encoding');
Expand All @@ -299,7 +290,7 @@ function respond(ctx) {

// responses
if (Buffer.isBuffer(body)) return res.end(body);
if ('string' === typeof body) return res.end(body);
if (typeof body === 'string') return res.end(body);
if (body instanceof Stream) return body.pipe(res);

// body: json
Expand Down
19 changes: 6 additions & 13 deletions lib/context.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@

'use strict';

/**
* Module dependencies.
*/

const util = require('util');
const createError = require('http-errors');
const httpAssert = require('http-assert');
Expand Down Expand Up @@ -53,7 +46,7 @@ const proto = module.exports = {
originalUrl: this.originalUrl,
req: '<original node req>',
res: '<original node res>',
socket: '<original node socket>'
socket: '<original node socket>',
};
},

Expand Down Expand Up @@ -108,7 +101,7 @@ const proto = module.exports = {
// don't do anything if there is no error.
// this allows you to pass `this.onerror`
// to node-style callbacks.
if (null == err) return;
if (err == null) return;

// When dealing with cross-globals a normal `instanceof` check doesn't work properly.
// See https://github.com/koajs/koa/issues/1466
Expand Down Expand Up @@ -152,10 +145,10 @@ const proto = module.exports = {
let statusCode = err.status || err.statusCode;

// ENOENT support
if ('ENOENT' === err.code) statusCode = 404;
if (err.code === 'ENOENT') statusCode = 404;

// default to 500
if ('number' !== typeof statusCode || !statuses[statusCode]) statusCode = 500;
if (typeof statusCode !== 'number' || !statuses[statusCode]) statusCode = 500;

// respond
const code = statuses[statusCode];
Expand All @@ -169,15 +162,15 @@ const proto = module.exports = {
if (!this[COOKIES]) {
this[COOKIES] = new Cookies(this.req, this.res, {
keys: this.app.keys,
secure: this.request.secure
secure: this.request.secure,
});
}
return this[COOKIES];
},

set cookies(_cookies) {
this[COOKIES] = _cookies;
}
},
};

/**
Expand Down
Loading

0 comments on commit 6a28f83

Please sign in to comment.