File tree Expand file tree Collapse file tree 9 files changed +42
-48
lines changed Expand file tree Collapse file tree 9 files changed +42
-48
lines changed Original file line number Diff line number Diff line change @@ -26,8 +26,5 @@ module.exports = {
26
26
'@types/koa' ,
27
27
'@types/koa-router' ,
28
28
] ,
29
- semver : [
30
- 'koa-bodyparser@2' ,
31
- ] ,
32
29
test : 'scripts' ,
33
30
} ;
Original file line number Diff line number Diff line change 1
1
sudo : false
2
2
language : node_js
3
3
node_js :
4
- - ' 6'
5
4
- ' 8'
6
5
- ' 9'
7
6
install :
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
const delegate = require ( 'delegates' ) ;
4
- const co = require ( 'co' ) ;
5
4
const { assign } = require ( 'utility' ) ;
6
5
7
6
const HELPER = Symbol ( 'Context#helper' ) ;
@@ -197,13 +196,15 @@ const proto = module.exports = {
197
196
const start = Date . now ( ) ;
198
197
/* istanbul ignore next */
199
198
const taskName = scope . name || '-' ;
200
- co ( function * ( ) {
201
- yield scope ( ctx ) ;
202
- ctx . coreLogger . info ( '[egg:background] task:%s success (%dms)' , taskName , Date . now ( ) - start ) ;
203
- } ) . catch ( err => {
204
- ctx . coreLogger . info ( '[egg:background] task:%s fail (%dms)' , taskName , Date . now ( ) - start ) ;
205
- ctx . coreLogger . error ( err ) ;
206
- } ) ;
199
+ // use app.toAsyncFunction to support both generator function and async function
200
+ ctx . app . toAsyncFunction ( scope ) ( ctx )
201
+ . then ( ( ) => {
202
+ ctx . coreLogger . info ( '[egg:background] task:%s success (%dms)' , taskName , Date . now ( ) - start ) ;
203
+ } )
204
+ . catch ( err => {
205
+ ctx . coreLogger . info ( '[egg:background] task:%s fail (%dms)' , taskName , Date . now ( ) - start ) ;
206
+ ctx . coreLogger . error ( err ) ;
207
+ } ) ;
207
208
} ,
208
209
} ;
209
210
Original file line number Diff line number Diff line change 5
5
'use strict' ;
6
6
7
7
module . exports = ( ) => {
8
- return function * meta ( next ) {
9
- yield next ;
8
+ return async function meta ( ctx , next ) {
9
+ await next ( ) ;
10
10
// total response time header
11
- this . set ( 'x-readtime' , Date . now ( ) - this . starttime ) ;
11
+ ctx . set ( 'x-readtime' , Date . now ( ) - ctx . starttime ) ;
12
12
} ;
13
13
} ;
Original file line number Diff line number Diff line change 1
1
'use strict' ;
2
2
3
3
module . exports = options => {
4
- return function * notfound ( next ) {
5
- yield next ;
4
+ return async function notfound ( ctx , next ) {
5
+ await next ( ) ;
6
6
7
- if ( this . status !== 404 || this . body ) {
7
+ if ( ctx . status !== 404 || ctx . body ) {
8
8
return ;
9
9
}
10
10
11
11
// set status first, make sure set body not set status
12
- this . status = 404 ;
12
+ ctx . status = 404 ;
13
13
14
- if ( this . acceptJSON ) {
15
- this . body = {
14
+ if ( ctx . acceptJSON ) {
15
+ ctx . body = {
16
16
message : 'Not Found' ,
17
17
} ;
18
18
return ;
@@ -21,16 +21,16 @@ module.exports = options => {
21
21
const notFoundHtml = '<h1>404 Not Found</h1>' ;
22
22
23
23
// notfound handler is unimplemented
24
- if ( options . pageUrl && this . path === options . pageUrl ) {
25
- this . body = `${ notFoundHtml } <p><pre><code>config.notfound.pageUrl(${ options . pageUrl } )</code></pre> is unimplemented</p>` ;
24
+ if ( options . pageUrl && ctx . path === options . pageUrl ) {
25
+ ctx . body = `${ notFoundHtml } <p><pre><code>config.notfound.pageUrl(${ options . pageUrl } )</code></pre> is unimplemented</p>` ;
26
26
return ;
27
27
}
28
28
29
29
if ( options . pageUrl ) {
30
- this . realStatus = 404 ;
31
- this . redirect ( options . pageUrl ) ;
30
+ ctx . realStatus = 404 ;
31
+ ctx . redirect ( options . pageUrl ) ;
32
32
return ;
33
33
}
34
- this . body = notFoundHtml ;
34
+ ctx . body = notFoundHtml ;
35
35
} ;
36
36
} ;
Original file line number Diff line number Diff line change @@ -4,27 +4,27 @@ const path = require('path');
4
4
const MAX_AGE = 'public, max-age=2592000' ; // 30 days
5
5
6
6
module . exports = options => {
7
- return function * siteFile ( next ) {
8
- if ( this . method !== 'HEAD' && this . method !== 'GET' ) return yield next ;
7
+ return function siteFile ( ctx , next ) {
8
+ if ( ctx . method !== 'HEAD' && ctx . method !== 'GET' ) return next ( ) ;
9
9
/* istanbul ignore if */
10
- if ( this . path [ 0 ] !== '/' ) return yield next ;
10
+ if ( ctx . path [ 0 ] !== '/' ) return next ( ) ;
11
11
12
- const content = options [ this . path ] ;
13
- if ( ! content ) return yield next ;
12
+ const content = options [ ctx . path ] ;
13
+ if ( ! content ) return next ( ) ;
14
14
15
15
// '/favicon.ico': 'https://eggjs.org/favicon.ico',
16
16
// content is url
17
- if ( typeof content === 'string' ) return this . redirect ( content ) ;
17
+ if ( typeof content === 'string' ) return ctx . redirect ( content ) ;
18
18
19
19
// '/robots.txt': Buffer <xx..
20
20
// content is buffer
21
21
if ( Buffer . isBuffer ( content ) ) {
22
- this . set ( 'cache-control' , MAX_AGE ) ;
23
- this . body = content ;
24
- this . type = path . extname ( this . path ) ;
22
+ ctx . set ( 'cache-control' , MAX_AGE ) ;
23
+ ctx . body = content ;
24
+ ctx . type = path . extname ( ctx . path ) ;
25
25
return ;
26
26
}
27
27
28
- yield next ;
28
+ return next ( ) ;
29
29
} ;
30
30
} ;
Original file line number Diff line number Diff line change 1
1
environment :
2
2
matrix :
3
- - nodejs_version : ' 6'
4
- - nodejs_version : ' 7'
5
3
- nodejs_version : ' 8'
4
+ - nodejs_version : ' 9'
6
5
7
6
install :
8
7
- ps : Install-Product node $env:nodejs_version
Original file line number Diff line number Diff line change @@ -398,11 +398,7 @@ class EggApplication extends EggCore {
398
398
client . create = ( ...args ) => {
399
399
const realClient = create . apply ( client , args ) ;
400
400
this [ CLUSTER_CLIENTS ] . push ( realClient ) ;
401
-
402
- this . beforeClose ( function * ( ) {
403
- yield cluster . close ( realClient ) ;
404
- } ) ;
405
-
401
+ this . beforeClose ( ( ) => cluster . close ( realClient ) ) ;
406
402
return realClient ;
407
403
} ;
408
404
}
Original file line number Diff line number Diff line change 19
19
"accepts" : " ^1.3.4" ,
20
20
"agentkeepalive" : " ^3.3.0" ,
21
21
"cluster-client" : " ^1.7.1" ,
22
- "co" : " ^4.6.0" ,
23
22
"debug" : " ^3.1.0" ,
24
23
"delegates" : " ^1.0.0" ,
25
24
"egg-cluster" : " ^1.12.4" ,
26
25
"egg-cookies" : " ^2.2.1" ,
27
- "egg-core" : " ^3.18 .0" ,
26
+ "egg-core" : " ^4.0 .0" ,
28
27
"egg-development" : " ^1.3.2" ,
29
28
"egg-i18n" : " ^1.2.0" ,
30
29
"egg-jsonp" : " ^1.2.1" ,
42
41
"graceful" : " ^1.0.1" ,
43
42
"humanize-ms" : " ^1.2.1" ,
44
43
"is-type-of" : " ^1.2.0" ,
45
- "koa-bodyparser" : " ^2.5 .0" ,
44
+ "koa-bodyparser" : " ^4.2 .0" ,
46
45
"koa-is-json" : " ^1.0.0" ,
47
- "koa-override" : " ^2 .0.0" ,
46
+ "koa-override" : " ^3 .0.0" ,
48
47
"mime-types" : " ^2.1.17" ,
49
48
"sendmessage" : " ^1.1.0" ,
50
49
"urllib" : " ^2.25.1" ,
107
106
"url" : " https://github.com/eggjs/egg.git"
108
107
},
109
108
"engines" : {
110
- "node" : " >= 6.0.0"
109
+ "node" : " >= 8.0.0"
110
+ },
111
+ "publishConfig" : {
112
+ "tag" : " next"
111
113
},
112
114
"license" : " MIT"
113
115
}
You can’t perform that action at this time.
0 commit comments