-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add documentation for routing Host introduced in 0.18.2 (#605)
- Loading branch information
Showing
4 changed files
with
68 additions
and
0 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,33 @@ | ||
## Hosts | ||
|
||
<%= sinceVersion("0.18.2") %> | ||
|
||
Buffalo apps also support grouping of end-points by host. `Host` creates a new group that matches the domain passed. This is useful for creating groups of end-points for different domains or subdomains. | ||
|
||
```go | ||
app := buffalo.New(buffalo.Options{ | ||
Env: envy.Get("GO_ENV", "development"), | ||
SessionName: "_coke_session", | ||
}) | ||
|
||
subApp := app.Host("docs.domain.com") | ||
subApp.GET("/", func (c buffalo.Context) error { | ||
return c.Render(http.StatusOK, r.String("docs.domain.com Homepage")) | ||
}) | ||
|
||
domainApp := app.Host("example.com") | ||
domainApp.GET("/", func (c buffalo.Context) error { | ||
return c.Render(http.StatusOK, r.String("example.com Homepage")) | ||
}) | ||
|
||
app.GET("/", func (c buffalo.Context) error { | ||
return c.Render(http.StatusOK, r.String("Main App Homepage")) | ||
}) | ||
``` | ||
|
||
Variables mapped to parameters are also supported: | ||
|
||
```go | ||
app.Host("{subdomain}.example.com") | ||
app.Host("{subdomain:[a-z]+}.example.com") | ||
``` |
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,33 @@ | ||
## Hôtes | ||
|
||
<%= sinceVersion("0.18.2") %> | ||
|
||
Buffalo supporte également le regroupement d'APIs par domaine. La méthode `Host` crée un nouveau groupe pour le nom de domaine passé en paramètre, ce qui peut être une méthode pratique pour regrouper des APIs appartenant au même domaine (voire gérer plusieurs sous-domaines sur une même application). | ||
|
||
```go | ||
app := buffalo.New(buffalo.Options{ | ||
Env: envy.Get("GO_ENV", "development"), | ||
SessionName: "_coke_session", | ||
}) | ||
|
||
subApp := app.Host("docs.domain.com") | ||
subApp.GET("/", func (c buffalo.Context) error { | ||
return c.Render(http.StatusOK, r.String("docs.domain.com Homepage")) | ||
}) | ||
|
||
domainApp := app.Host("example.com") | ||
domainApp.GET("/", func (c buffalo.Context) error { | ||
return c.Render(http.StatusOK, r.String("example.com Homepage")) | ||
}) | ||
|
||
app.GET("/", func (c buffalo.Context) error { | ||
return c.Render(http.StatusOK, r.String("Main App Homepage")) | ||
}) | ||
``` | ||
|
||
Les variables associéees aux paramètres sont également prises en charge : | ||
|
||
```go | ||
app.Host("{subdomain}.example.com") | ||
app.Host("{subdomain:[a-z]+}.example.com") | ||
``` |