Skip to content

Commit

Permalink
docs(basic-router):fix some places of basic-router (#2012)
Browse files Browse the repository at this point in the history
  • Loading branch information
SunShinewyf authored and dead-horse committed Jan 24, 2018
1 parent c4fbf61 commit 1e3a4b3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion docs/source/en/basics/middleware.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
18 changes: 9 additions & 9 deletions docs/source/en/basics/router.md
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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,

Expand All @@ -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
Expand All @@ -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
-------|-----------------|----------------|-----------------------------
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1e3a4b3

Please sign in to comment.