diff --git a/docs/source/en/basics/middleware.md b/docs/source/en/basics/middleware.md index 132776245f..accd0bd6c5 100644 --- a/docs/source/en/basics/middleware.md +++ b/docs/source/en/basics/middleware.md @@ -118,7 +118,7 @@ Middlewares which are defined at Application (`app.config.appMiddleware`) and Fr The middleware configured in the above ways is global, and it will process every request. -If you do want to take only for single route, you could just instantiate and mount it at `app/router.js`: +If you do want to take effect only for single route, you could just instantiate and mount it at `app/router.js`: ```js module.exports = app => { diff --git a/docs/source/en/basics/router.md b/docs/source/en/basics/router.md index 22c2bc2571..035742f257 100644 --- a/docs/source/en/basics/router.md +++ b/docs/source/en/basics/router.md @@ -1,9 +1,9 @@ title: Router --- -Router is mainly used to describe the relationship between the request URL and the Controller that processes the request eventually. All routing rules are unified in the `app/router.js` file by the framework. +Router is mainly used to describe the corresponding relationship between the request URL and the Controller that processes the request eventually. All routing rules are unified in the `app/router.js` file by the framework. -By unifying routing rules, routing logics are free from scatter that may cause unkown conflicts and it will be easier for us to check global routing rules. +By unifying routing rules, we can avoid the routing logics scattered in many places which may cause many unknown conflicts, and we can more easily check global routing rules. ## How to Define Router @@ -55,8 +55,8 @@ The complete definition of router includes 5 major parts: * router.redirect - redirects the request URL. For example, the most common case is to redirect the request accessing the root directory to the homepage. - router-name defines a alias for the route, and URL can be generated by helper method `pathFor` and `urlFor` provided by Helper. (Optional) - path-match - URL path of the route. -- middleware1 - multiple Middleware can be configured in Router. (Optional) -- controller - specific the controller of this router, this param can be tow types: +- middleware1 - multiple Middlewares can be configured in Router. (Optional) +- controller - set the route to map to the specific controller, and the controller can be written in two types: * `app.controller.user.fetch` - directly point to a controller * `'user.fetch'` - simplified as a string, @@ -83,7 +83,7 @@ module.exports = app => { ### RESTful style URL definition -We provide `app.resources('router-name', 'path-match', 'controller-name')` to generate [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) structures on a path for convenience if you prefer the RESTful style URL definition. +We provide `app.resources('routerName', 'pathMatch', 'controller')` to generate [CRUD](https://en.wikipedia.org/wiki/Create,_read,_update_and_delete) structures on a path for convenience if you prefer the RESTful style URL definition. ```js // app/router.js @@ -94,7 +94,7 @@ module.exports = app => { }; ``` -The codes above produces a bunch of CRUD path structures for Controller `app/controller/posts.js`, and the only thing you should do next is to implement related functions in `posts.js`. +The codes above produce a bunch of CRUD path structures for Controller `app/controller/posts.js`, and the only thing you should do next is to implement related functions in `posts.js`. Method | Path | Route Name | Controller.Action -------|-----------------|----------------|----------------------------- @@ -165,7 +165,7 @@ exports.info = async ctx => { #### acquiring complex parameters -Regular expressions, as well, can be used in routing rules to aquire parameters more flexibly: +Regular expressions, as well, can be used in routing rules to acquire parameters more flexibly: ```js // app/router.js @@ -204,7 +204,7 @@ exports.post = async ctx => { > If you perform a POST request directly, an **error** will occur: 'secret is missing'. This error message comes from [koa-csrf/index.js#L69](https://github.com/koajs/csrf/blob/2.5.0/index.js#L69). -> **Reason**: the framework verifies the CSFR value specially for form POST requests, so please submit the CSRF key as well when you submit a form. For more detail refer to [Keep Away from CSRF Threat](https://eggjs.org/zh-cn/core/security.html#安全威胁csrf的防范) +> **Reason**: the framework verifies the CSFR value specially for form POST requests, so please submit the CSRF key as well when you submit a form. Refer to [Keep Away from CSRF Threat](https://eggjs.org/zh-cn/core/security.html#安全威胁csrf的防范) for more detail. > **Note**: the verification is performed because the framework builds in a security plugin [egg-security](https://github.com/eggjs/egg-security) that provides some default security practices and this plugin is enabled by default. In case you want to disable some security protections, just set the enable attribute to false. @@ -319,7 +319,7 @@ module.exports = app => { As described above, we do not recommend that you scatter routing logics all around, or it will bring trouble in trouble shooting. -If it is a must for some reasons, you can split routing rules like below: +If there is a need for some reasons, you can split routing rules like below: ```js // app/router.js