mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 10:27:06 +00:00
create the new FileServer and HandleDir, deprecate the rest APIBuilder/Party static methods and more
relative: https://github.com/kataras/iris/issues/1283 and removing pongo2 from vendor: https://github.com/kataras/iris/issues/1284 Former-commit-id: 3ec57b349f99faca2b8e36d9f7252db0b6ea080d
This commit is contained in:
@@ -4,38 +4,48 @@ import (
|
||||
"github.com/kataras/iris"
|
||||
)
|
||||
|
||||
func main() {
|
||||
func newApp() *iris.Application {
|
||||
app := iris.New()
|
||||
|
||||
app.Favicon("./assets/favicon.ico")
|
||||
|
||||
// enable gzip, optionally:
|
||||
// if used before the `StaticXXX` handlers then
|
||||
// the content byte range feature is gone.
|
||||
// recommend: turn off for large files especially
|
||||
// when server has low memory,
|
||||
// turn on for medium-sized files
|
||||
// or for large-sized files if they are zipped already,
|
||||
// i.e "zippedDir/file.gz"
|
||||
//
|
||||
// app.Use(iris.Gzip)
|
||||
|
||||
// first parameter is the request path
|
||||
// second is the system directory
|
||||
//
|
||||
// app.StaticWeb("/css", "./assets/css")
|
||||
// app.StaticWeb("/js", "./assets/js")
|
||||
//
|
||||
app.StaticWeb("/static", "./assets")
|
||||
// app.HandleDir("/css", "./assets/css")
|
||||
// app.HandleDir("/js", "./assets/js")
|
||||
|
||||
app.HandleDir("/static", "./assets", iris.DirOptions{
|
||||
// Defaults to "/index.html", if request path is ending with **/*/$IndexName
|
||||
// then it redirects to **/*(/) which another handler is handling it,
|
||||
// that another handler, called index handler, is auto-registered by the framework
|
||||
// if end developer does not managed to handle it by hand.
|
||||
IndexName: "/index.html",
|
||||
// When files should served under compression.
|
||||
Gzip: false,
|
||||
// List the files inside the current requested directory if `IndexName` not found.
|
||||
ShowList: false,
|
||||
// If `ShowList` is true then this function will be used instead of the default one to show the list of files of a current requested directory(dir).
|
||||
// DirList: func(ctx context.Context, dirName string, dir http.File) error { ... }
|
||||
//
|
||||
// Optional validator that loops through each requested resource.
|
||||
// AssetValidator: func(ctx iris.Context, name string) bool { ... }
|
||||
})
|
||||
|
||||
// You can also register any index handler manually, order of registration does not matter:
|
||||
// app.Get("/static", [...custom middleware...], func(ctx iris.Context) {
|
||||
// [...custom code...]
|
||||
// ctx.ServeFile("./assets/index.html", false)
|
||||
// })
|
||||
|
||||
// http://localhost:8080/static
|
||||
// http://localhost:8080/static/css/main.css
|
||||
// http://localhost:8080/static/js/jquery-2.1.1.js
|
||||
// http://localhost:8080/static/favicon.ico
|
||||
app.Run(iris.Addr(":8080"))
|
||||
|
||||
// Note:
|
||||
// Routing doesn't allows something .StaticWeb("/", "./assets")
|
||||
//
|
||||
// To see how you can wrap the router in order to achieve
|
||||
// wildcard on root path, see "single-page-application".
|
||||
return app
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := newApp()
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user