Skip to content

Update README with more info about custom routes #476

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,19 @@ Now you can access resources using additional routes.
/blog/javascript # → /posts?category=javascript
```

When using custom routes, routes that don't contain params will match any request for which the route path is a prefix of the request URL and replace that prefix with the value they map to. Place routes with parameters first to avoid route collisions.

For example, if you define the following:

```json
{
"/blog/categories": "/categories",
"/blog/categories/:category/posts": "/posts?category=:category"
}
```

A request to `blog/categories/js/posts` will match the first route and get replaced with `/categories/js/posts`, not `/posts?category=js` as intended. Swapping the routes solves this issue.

### Add middlewares

You can add your middlewares from the CLI using `--middlewares` option:
Expand Down