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 = '
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