-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: support custom pathToRegexpModule on app.options (#290)
deps on - eggjs/router#18 - eggjs/egg-path-matching#11
- Loading branch information
Showing
23 changed files
with
568 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
name: Release for 5.x | ||
on: | ||
push: | ||
branches: [ 5.x ] | ||
|
||
jobs: | ||
release: | ||
name: Node.js | ||
uses: eggjs/github-actions/.github/workflows/node-release.yml@master | ||
secrets: | ||
NPM_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
GIT_TOKEN: ${{ secrets.GIT_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
test/fixtures/router-app-with-pathToRegexpModule/app/controller/async.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = app => { | ||
return class AsyncController extends app.Controller { | ||
async index() { | ||
this.ctx.body.push('async'); | ||
} | ||
} | ||
}; |
15 changes: 15 additions & 0 deletions
15
test/fixtures/router-app-with-pathToRegexpModule/app/controller/comments.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
'use strict'; | ||
|
||
// 测试 app.resources 遇到 controller 没有足够的 action 的场景 | ||
|
||
exports.index = function* () { | ||
this.body = 'index'; | ||
}; | ||
|
||
exports.new = function* () { | ||
this.body = 'new'; | ||
}; | ||
|
||
exports.show = function* () { | ||
this.body = 'show - ' + this.params.id; | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/fixtures/router-app-with-pathToRegexpModule/app/controller/locals.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
exports.router = function* () { | ||
yield this.render('locals/router.html'); | ||
}; |
19 changes: 19 additions & 0 deletions
19
test/fixtures/router-app-with-pathToRegexpModule/app/controller/members.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
'use strict'; | ||
|
||
// 测试 app.resources 遇到 controller 没有足够的 action 的场景 | ||
|
||
exports.index = function* () { | ||
this.body = 'index'; | ||
}; | ||
|
||
exports.new = function* () { | ||
this.body = 'new'; | ||
}; | ||
|
||
exports.show = function* () { | ||
this.body = 'show - ' + this.params.id; | ||
}; | ||
|
||
exports.delete = function* () { | ||
this.body = `delete - ${this.params.id}`; | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/fixtures/router-app-with-pathToRegexpModule/app/controller/middleware.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
module.exports = function* () { | ||
this.body = []; | ||
}; |
5 changes: 5 additions & 0 deletions
5
test/fixtures/router-app-with-pathToRegexpModule/app/controller/package.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
'use strict'; | ||
|
||
exports.get = function* () { | ||
this.body = this.params[0]; | ||
}; |
29 changes: 29 additions & 0 deletions
29
test/fixtures/router-app-with-pathToRegexpModule/app/controller/posts.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
'use strict'; | ||
|
||
exports.index = function* () { | ||
this.body = 'index'; | ||
}; | ||
|
||
exports.new = function* () { | ||
this.body = 'new'; | ||
}; | ||
|
||
exports.create = function* () { | ||
this.body = 'create'; | ||
}; | ||
|
||
exports.show = function* () { | ||
this.body = 'show - ' + this.params.id; | ||
}; | ||
|
||
exports.edit = function* () { | ||
this.body = 'edit - ' + this.params.id; | ||
}; | ||
|
||
exports.update = function* () { | ||
this.body = 'update - ' + this.params.id; | ||
}; | ||
|
||
exports.destroy = function* () { | ||
this.body = 'destroy - ' + this.params.id; | ||
}; |
8 changes: 8 additions & 0 deletions
8
test/fixtures/router-app-with-pathToRegexpModule/app/middleware/async.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
module.exports = function() { | ||
return async (ctx, next) => { | ||
await next(); | ||
ctx.body.push('async'); | ||
}; | ||
}; |
9 changes: 9 additions & 0 deletions
9
test/fixtures/router-app-with-pathToRegexpModule/app/middleware/common.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
module.exports = function() { | ||
return function(ctx, next) { | ||
return next().then(() => { | ||
ctx.body.push('common'); | ||
}); | ||
}; | ||
}; |
8 changes: 8 additions & 0 deletions
8
test/fixtures/router-app-with-pathToRegexpModule/app/middleware/generator.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
'use strict'; | ||
|
||
module.exports = function() { | ||
return function*(next) { | ||
yield next; | ||
this.body.push('generator'); | ||
}; | ||
}; |
10 changes: 10 additions & 0 deletions
10
test/fixtures/router-app-with-pathToRegexpModule/app/middleware/generator_both.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
'use strict'; | ||
|
||
module.exports = function() { | ||
return function*(next) { | ||
this.body = []; | ||
this.body.push('generator before'); | ||
yield next; | ||
this.body.push('generator after'); | ||
}; | ||
}; |
34 changes: 34 additions & 0 deletions
34
test/fixtures/router-app-with-pathToRegexpModule/app/router.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
module.exports = function (app) { | ||
const common = app.middlewares.common(); | ||
const asyncMw = app.middlewares.async(); | ||
const generator = app.middlewares.generator(); | ||
const generatorBoth = app.middlewares.generatorBoth(); | ||
|
||
app | ||
.get('/locals/router', app.controller.locals.router) | ||
.get('/members/index', 'members.index') | ||
.delete('/members/delete/:id', 'members.delete') | ||
.del('/members/del/:id', 'members.delete') | ||
.resources('posts', '/posts', 'posts') | ||
.resources('members', '/members', app.controller.members) | ||
.resources('/comments', app.controller.comments) | ||
// not work on path-to-regexp@8 | ||
// .get('comment_index', '/comments/:id?filter=', app.controller.comments.index) | ||
.get('params', '/params/:a/:b', app.controller.locals.router) | ||
.get('/middleware', common, asyncMw, generator, 'middleware') | ||
.get('middleware', '/named_middleware', common, asyncMw, generator, 'middleware') | ||
.get('/mix', generatorBoth , 'async.index') | ||
.register('/comments', [ 'post' ] , app.controller.comments.new) | ||
.register('/register_middleware', [ 'get' ], [ common, asyncMw, generator, 'middleware' ]) | ||
.redirect('/redirect', '/middleware', 302); | ||
|
||
app.router | ||
.get('/router_middleware', common, asyncMw, generator, 'middleware') | ||
.redirect('/router_redirect', '/middleware'); | ||
|
||
// not work on path-to-regexp@8 | ||
// app.get('packages', /^\/packages\/(.*)/, 'package.get'); | ||
|
||
app.get([ '/url1', '/url2' ], 'members.index') | ||
app.get([ '/urlm1', '/urlm2' ], common, asyncMw, generator, 'middleware') | ||
}; |
1 change: 1 addition & 0 deletions
1
test/fixtures/router-app-with-pathToRegexpModule/app/views/locals/router.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
posts: /posts |
9 changes: 9 additions & 0 deletions
9
test/fixtures/router-app-with-pathToRegexpModule/config/config.default.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
'use strict'; | ||
|
||
exports.keys = 'my'; | ||
|
||
exports.security = { | ||
csrf: { | ||
enable: false, | ||
}, | ||
}; |
3 changes: 3 additions & 0 deletions
3
test/fixtures/router-app-with-pathToRegexpModule/package.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"name": "router-app-with-pathToRegexpModule" | ||
} |
Oops, something went wrong.