mirror of
https://github.com/kataras/iris.git
synced 2026-01-09 04:51:56 +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:
37
iris.go
37
iris.go
@@ -187,6 +187,41 @@ func Default() *Application {
|
||||
return app
|
||||
}
|
||||
|
||||
// WWW creates and returns a "www." subdomain.
|
||||
// The difference from `app.Subdomain("www")` or `app.Party("www.")` is that the `app.WWW()` method
|
||||
// wraps the router so all http(s)://mydomain.com will be redirect to http(s)://www.mydomain.com.
|
||||
// Other subdomains can be registered using the app: `sub := app.Subdomain("mysubdomain")`,
|
||||
// child subdomains can be registered using the www := app.WWW(); www.Subdomain("wwwchildSubdomain").
|
||||
func (app *Application) WWW() router.Party {
|
||||
return app.SubdomainRedirect(app, app.Subdomain("www"))
|
||||
}
|
||||
|
||||
// SubdomainRedirect registers a router wrapper which
|
||||
// redirects(StatusMovedPermanently) a (sub)domain to another subdomain or to the root domain as fast as possible,
|
||||
// before the router's try to execute route's handler(s).
|
||||
//
|
||||
// It receives two arguments, they are the from and to/target locations,
|
||||
// 'from' can be a wildcard subdomain as well (app.WildcardSubdomain())
|
||||
// 'to' is not allowed to be a wildcard for obvious reasons,
|
||||
// 'from' can be the root domain(app) when the 'to' is not the root domain and visa-versa.
|
||||
//
|
||||
// Usage:
|
||||
// www := app.Subdomain("www") <- same as app.Party("www.")
|
||||
// app.SubdomainRedirect(app, www)
|
||||
// This will redirect all http(s)://mydomain.com/%anypath% to http(s)://www.mydomain.com/%anypath%.
|
||||
//
|
||||
// One or more subdomain redirects can be used to the same app instance.
|
||||
//
|
||||
// If you need more information about this implementation then you have to navigate through
|
||||
// the `core/router#NewSubdomainRedirectWrapper` function instead.
|
||||
//
|
||||
// Example: https://github.com/kataras/iris/tree/master/_examples/subdomains/redirect
|
||||
func (app *Application) SubdomainRedirect(from, to router.Party) router.Party {
|
||||
sd := router.NewSubdomainRedirectWrapper(app.ConfigurationReadOnly().GetVHost, from.GetRelPath(), to.GetRelPath())
|
||||
app.WrapRouter(sd)
|
||||
return to
|
||||
}
|
||||
|
||||
// Configure can called when modifications to the framework instance needed.
|
||||
// It accepts the framework instance
|
||||
// and returns an error which if it's not nil it's printed to the logger.
|
||||
@@ -670,7 +705,7 @@ var ErrServerClosed = http.ErrServerClosed
|
||||
// `Listener`, `Server`, `Addr`, `TLS`, `AutoTLS` and `Raw`.
|
||||
func (app *Application) Run(serve Runner, withOrWithout ...Configurator) error {
|
||||
// first Build because it doesn't need anything from configuration,
|
||||
// this give the user the chance to modify the router inside a configurator as well.
|
||||
// this give the user the chance to modify the router inside a configurator as well.
|
||||
if err := app.Build(); err != nil {
|
||||
return errors.PrintAndReturnErrors(err, app.logger.Errorf)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user