Skip to content
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

Add documentation for routing Host introduced in 0.18.2 #605

Merged
merged 3 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
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
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")
```