From 93bd3b6a33e1a70e9ad0b8ffb46c43505811a196 Mon Sep 17 00:00:00 2001 From: Stefan Aurori Date: Fri, 24 Dec 2021 07:00:43 -0500 Subject: [PATCH] Add documentation for routing Host introduced in 0.18.2 (#605) --- templates/en/docs/routing.md | 1 + templates/en/docs/routing/_hosts.md | 33 +++++++++++++++++++++++++++++ templates/fr/docs/routing.md | 1 + templates/fr/docs/routing/_hosts.md | 33 +++++++++++++++++++++++++++++ 4 files changed, 68 insertions(+) create mode 100644 templates/en/docs/routing/_hosts.md create mode 100644 templates/fr/docs/routing/_hosts.md diff --git a/templates/en/docs/routing.md b/templates/en/docs/routing.md index 96ee874ca..133a553c3 100644 --- a/templates/en/docs/routing.md +++ b/templates/en/docs/routing.md @@ -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") %> diff --git a/templates/en/docs/routing/_hosts.md b/templates/en/docs/routing/_hosts.md new file mode 100644 index 000000000..f5c09e2dc --- /dev/null +++ b/templates/en/docs/routing/_hosts.md @@ -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") +``` diff --git a/templates/fr/docs/routing.md b/templates/fr/docs/routing.md index 746cccfcc..9d72317c3 100644 --- a/templates/fr/docs/routing.md +++ b/templates/fr/docs/routing.md @@ -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") %> diff --git a/templates/fr/docs/routing/_hosts.md b/templates/fr/docs/routing/_hosts.md new file mode 100644 index 000000000..7fda22739 --- /dev/null +++ b/templates/fr/docs/routing/_hosts.md @@ -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") +```