mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 19:37:03 +00:00
NEW: Application#SubdomainRedirect. Example: https://github.com/kataras/iris/blob/master/_examples/subdomains/redirect/main.go
Former-commit-id: d8dd7c426dc9f14c870f103fef703595a2915612
This commit is contained in:
@@ -11,25 +11,41 @@ func newApp() *iris.Application {
|
||||
app.Get("/about", info)
|
||||
app.Get("/contact", info)
|
||||
|
||||
usersAPI := app.Party("/api/users")
|
||||
{
|
||||
usersAPI.Get("/", info)
|
||||
usersAPI.Get("/{id:int}", info)
|
||||
app.PartyFunc("/api/users", func(r iris.Party) {
|
||||
r.Get("/", info)
|
||||
r.Get("/{id:int}", info)
|
||||
|
||||
usersAPI.Post("/", info)
|
||||
r.Post("/", info)
|
||||
|
||||
usersAPI.Put("/{id:int}", info)
|
||||
}
|
||||
r.Put("/{id:int}", info)
|
||||
}) /* <- same as:
|
||||
usersAPI := app.Party("/api/users")
|
||||
{ // those brackets are just syntactic-sugar things.
|
||||
// This method is rarely used but you can make use of it when you want
|
||||
// scoped variables to that code block only.
|
||||
usersAPI.Get/Post...
|
||||
}
|
||||
usersAPI.Get/Post...
|
||||
*/
|
||||
|
||||
www := app.Party("www.")
|
||||
{
|
||||
// get all routes that are registered so far, including all "Parties" but subdomains:
|
||||
// http://www.mydomain.com/hi
|
||||
www.Get("/hi", func(ctx iris.Context) {
|
||||
ctx.Writef("hi from www.mydomain.com")
|
||||
})
|
||||
|
||||
// Just to show how you can get all routes and copy them to another
|
||||
// party or subdomain:
|
||||
// Get all routes that are registered so far, including all "Parties" but subdomains:
|
||||
currentRoutes := app.GetRoutes()
|
||||
// register them to the www subdomain/vhost as well:
|
||||
// Register them to the www subdomain/vhost as well:
|
||||
for _, r := range currentRoutes {
|
||||
www.Handle(r.Method, r.Path, r.Handlers...)
|
||||
}
|
||||
}
|
||||
// See also the "subdomains/redirect" to register redirect router wrappers between subdomains,
|
||||
// i.e mydomain.com to www.mydomain.com (like facebook does for SEO reasons(;)).
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -43,6 +59,7 @@ func main() {
|
||||
// http://mydomain.com/api/users/42
|
||||
|
||||
// http://www.mydomain.com
|
||||
// http://www.mydomain.com/hi
|
||||
// http://www.mydomain.com/about
|
||||
// http://www.mydomain.com/contact
|
||||
// http://www.mydomain.com/api/users
|
||||
|
||||
Reference in New Issue
Block a user