Skip to content

Commit

Permalink
Add documentation for routing Host introduced in 0.18.2 (#605)
Browse files Browse the repository at this point in the history
  • Loading branch information
saurori authored Dec 24, 2021
1 parent 652874c commit 93bd3b6
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
1 change: 1 addition & 0 deletions templates/en/docs/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Buffalo uses the [github.com/gorilla/mux](http://www.gorillatoolkit.org/pkg/mux)
<%= partial("en/docs/routing/params.md") %>
<%= partial("en/docs/routing/named_params.md") %>
<%= partial("en/docs/routing/groups.md") %>
<%= partial("en/docs/routing/hosts.md") %>
<%= partial("en/docs/routing/mounting.md") %>
33 changes: 33 additions & 0 deletions templates/en/docs/routing/_hosts.md
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")
```
1 change: 1 addition & 0 deletions templates/fr/docs/routing.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ Buffalo utilise le paquet [github.com/gorilla/mux](http://www.gorillatoolkit.org
<%= partial("fr/docs/routing/params.md") %>
<%= partial("fr/docs/routing/named_params.md") %>
<%= partial("fr/docs/routing/groups.md") %>
<%= partial("fr/docs/routing/hosts.md") %>
<%= partial("fr/docs/routing/mounting.md") %>
33 changes: 33 additions & 0 deletions templates/fr/docs/routing/_hosts.md
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")
```

0 comments on commit 93bd3b6

Please sign in to comment.