mirror of
https://github.com/kataras/iris.git
synced 2025-12-27 06:47:08 +00:00
app. SPA from router wrapper to a simple handler, works faster now. Iris' router respects wildcards with other paths as well (unique) for almost a half year now... so we don't need a whole wrapper for those things anymore, fixes https://github.com/kataras/iris/issues/807
Former-commit-id: 5bd7f24997bb025a01bb92960a1bf255f073a228
This commit is contained in:
13
iris.go
13
iris.go
@@ -334,19 +334,14 @@ var (
|
||||
|
||||
// SPA accepts an "assetHandler" which can be the result of an
|
||||
// app.StaticHandler or app.StaticEmbeddedHandler.
|
||||
// It wraps the router and checks:
|
||||
// if it;s an asset, if the request contains "." (this behavior can be changed via /core/router.NewSPABuilder),
|
||||
// if the request is index, redirects back to the "/" in order to let the root handler to be executed,
|
||||
// if it's not an asset then it executes the router, so the rest of registered routes can be
|
||||
// executed without conflicts with the file server ("assetHandler").
|
||||
//
|
||||
// Use that instead of `StaticWeb` for root "/" file server.
|
||||
// Use that when you want to navigate from /index.html to / automatically
|
||||
// it's a helper function which just makes some checks based on the `IndexNames` and `AssetValidators`
|
||||
// before the assetHandler call.
|
||||
//
|
||||
// Example: https://github.com/kataras/iris/tree/master/_examples/file-server/single-page-application
|
||||
func (app *Application) SPA(assetHandler context.Handler) *router.SPABuilder {
|
||||
s := router.NewSPABuilder(assetHandler)
|
||||
wrapper := s.BuildWrapper(app.ContextPool)
|
||||
app.Router.WrapRouter(wrapper)
|
||||
app.APIBuilder.HandleMany("GET HEAD", "/{f:path}", s.Handler)
|
||||
return s
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user