diff --git a/.autod.conf.js b/.autod.conf.js index cac3312124..a573b24e6d 100644 --- a/.autod.conf.js +++ b/.autod.conf.js @@ -26,8 +26,5 @@ module.exports = { '@types/koa', '@types/koa-router', ], - semver: [ - 'koa-bodyparser@2', - ], test: 'scripts', }; diff --git a/.travis.yml b/.travis.yml index 29d6351511..ad743fb435 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ sudo: false language: node_js node_js: - - '6' - '8' - '9' install: diff --git a/app/extend/context.js b/app/extend/context.js index df9f6a9f76..1597e842bf 100644 --- a/app/extend/context.js +++ b/app/extend/context.js @@ -1,7 +1,6 @@ 'use strict'; const delegate = require('delegates'); -const co = require('co'); const { assign } = require('utility'); const HELPER = Symbol('Context#helper'); @@ -197,13 +196,15 @@ const proto = module.exports = { const start = Date.now(); /* istanbul ignore next */ const taskName = scope.name || '-'; - co(function* () { - yield scope(ctx); - ctx.coreLogger.info('[egg:background] task:%s success (%dms)', taskName, Date.now() - start); - }).catch(err => { - ctx.coreLogger.info('[egg:background] task:%s fail (%dms)', taskName, Date.now() - start); - ctx.coreLogger.error(err); - }); + // use app.toAsyncFunction to support both generator function and async function + ctx.app.toAsyncFunction(scope)(ctx) + .then(() => { + ctx.coreLogger.info('[egg:background] task:%s success (%dms)', taskName, Date.now() - start); + }) + .catch(err => { + ctx.coreLogger.info('[egg:background] task:%s fail (%dms)', taskName, Date.now() - start); + ctx.coreLogger.error(err); + }); }, }; diff --git a/app/middleware/meta.js b/app/middleware/meta.js index b0da79186f..efef61c2c9 100644 --- a/app/middleware/meta.js +++ b/app/middleware/meta.js @@ -5,9 +5,9 @@ 'use strict'; module.exports = () => { - return function* meta(next) { - yield next; + return async function meta(ctx, next) { + await next(); // total response time header - this.set('x-readtime', Date.now() - this.starttime); + ctx.set('x-readtime', Date.now() - ctx.starttime); }; }; diff --git a/app/middleware/notfound.js b/app/middleware/notfound.js index daaf28705b..4ec4288f8e 100644 --- a/app/middleware/notfound.js +++ b/app/middleware/notfound.js @@ -1,18 +1,18 @@ 'use strict'; module.exports = options => { - return function* notfound(next) { - yield next; + return async function notfound(ctx, next) { + await next(); - if (this.status !== 404 || this.body) { + if (ctx.status !== 404 || ctx.body) { return; } // set status first, make sure set body not set status - this.status = 404; + ctx.status = 404; - if (this.acceptJSON) { - this.body = { + if (ctx.acceptJSON) { + ctx.body = { message: 'Not Found', }; return; @@ -21,16 +21,16 @@ module.exports = options => { const notFoundHtml = '

404 Not Found

'; // notfound handler is unimplemented - if (options.pageUrl && this.path === options.pageUrl) { - this.body = `${notFoundHtml}

config.notfound.pageUrl(${options.pageUrl})
is unimplemented

`; + if (options.pageUrl && ctx.path === options.pageUrl) { + ctx.body = `${notFoundHtml}

config.notfound.pageUrl(${options.pageUrl})
is unimplemented

`; return; } if (options.pageUrl) { - this.realStatus = 404; - this.redirect(options.pageUrl); + ctx.realStatus = 404; + ctx.redirect(options.pageUrl); return; } - this.body = notFoundHtml; + ctx.body = notFoundHtml; }; }; diff --git a/app/middleware/site_file.js b/app/middleware/site_file.js index 2fde8e5746..bca4307727 100644 --- a/app/middleware/site_file.js +++ b/app/middleware/site_file.js @@ -4,27 +4,27 @@ const path = require('path'); const MAX_AGE = 'public, max-age=2592000'; // 30 days module.exports = options => { - return function* siteFile(next) { - if (this.method !== 'HEAD' && this.method !== 'GET') return yield next; + return function siteFile(ctx, next) { + if (ctx.method !== 'HEAD' && ctx.method !== 'GET') return next(); /* istanbul ignore if */ - if (this.path[0] !== '/') return yield next; + if (ctx.path[0] !== '/') return next(); - const content = options[this.path]; - if (!content) return yield next; + const content = options[ctx.path]; + if (!content) return next(); // '/favicon.ico': 'https://eggjs.org/favicon.ico', // content is url - if (typeof content === 'string') return this.redirect(content); + if (typeof content === 'string') return ctx.redirect(content); // '/robots.txt': Buffer { const realClient = create.apply(client, args); this[CLUSTER_CLIENTS].push(realClient); - - this.beforeClose(function* () { - yield cluster.close(realClient); - }); - + this.beforeClose(() => cluster.close(realClient)); return realClient; }; } diff --git a/package.json b/package.json index b1217e39d2..3412f7e318 100644 --- a/package.json +++ b/package.json @@ -19,12 +19,11 @@ "accepts": "^1.3.4", "agentkeepalive": "^3.3.0", "cluster-client": "^1.7.1", - "co": "^4.6.0", "debug": "^3.1.0", "delegates": "^1.0.0", "egg-cluster": "^1.12.4", "egg-cookies": "^2.2.1", - "egg-core": "^3.18.0", + "egg-core": "^4.0.0", "egg-development": "^1.3.2", "egg-i18n": "^1.2.0", "egg-jsonp": "^1.2.1", @@ -42,9 +41,9 @@ "graceful": "^1.0.1", "humanize-ms": "^1.2.1", "is-type-of": "^1.2.0", - "koa-bodyparser": "^2.5.0", + "koa-bodyparser": "^4.2.0", "koa-is-json": "^1.0.0", - "koa-override": "^2.0.0", + "koa-override": "^3.0.0", "mime-types": "^2.1.17", "sendmessage": "^1.1.0", "urllib": "^2.25.1", @@ -107,7 +106,10 @@ "url": "https://github.com/eggjs/egg.git" }, "engines": { - "node": ">= 6.0.0" + "node": ">= 8.0.0" + }, + "publishConfig": { + "tag": "next" }, "license": "MIT" }