2017-06-15 19:02:08 +02:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2019-10-25 00:27:02 +02:00
|
|
|
"github.com/kataras/iris/v12"
|
2017-06-15 19:02:08 +02:00
|
|
|
)
|
|
|
|
|
2019-06-21 18:43:25 +02:00
|
|
|
func newApp() *iris.Application {
|
2017-06-15 19:02:08 +02:00
|
|
|
app := iris.New()
|
|
|
|
|
|
|
|
app.Favicon("./assets/favicon.ico")
|
|
|
|
|
|
|
|
// first parameter is the request path
|
|
|
|
// second is the system directory
|
|
|
|
//
|
2019-06-21 18:43:25 +02:00
|
|
|
// app.HandleDir("/css", "./assets/css")
|
|
|
|
// app.HandleDir("/js", "./assets/js")
|
|
|
|
|
2019-11-13 18:14:56 +01:00
|
|
|
v1 := app.Party("/v1")
|
|
|
|
v1.HandleDir("/static", "./assets", iris.DirOptions{
|
2019-06-21 18:43:25 +02:00
|
|
|
// 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.
|
2020-07-10 22:21:09 +02:00
|
|
|
Compress: false,
|
2019-06-21 18:43:25 +02:00
|
|
|
// 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).
|
2019-08-11 14:43:47 +02:00
|
|
|
// DirList: func(ctx iris.Context, dirName string, dir http.File) error { ... }
|
2019-06-21 18:43:25 +02:00
|
|
|
//
|
|
|
|
// 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:
|
2019-11-13 18:14:56 +01:00
|
|
|
// v1.Get("/static", [...custom middleware...], func(ctx iris.Context) {
|
2019-06-21 18:43:25 +02:00
|
|
|
// [...custom code...]
|
2020-05-05 21:03:01 +02:00
|
|
|
// ctx.ServeFile("./assets/index.html")
|
2019-06-21 18:43:25 +02:00
|
|
|
// })
|
2017-06-15 19:02:08 +02:00
|
|
|
|
2019-11-13 18:14:56 +01:00
|
|
|
// http://localhost:8080/v1/static
|
|
|
|
// http://localhost:8080/v1/static/css/main.css
|
|
|
|
// http://localhost:8080/v1/static/js/jquery-2.1.1.js
|
|
|
|
// http://localhost:8080/v1/static/favicon.ico
|
2019-06-21 18:43:25 +02:00
|
|
|
return app
|
|
|
|
}
|
2017-06-15 19:02:08 +02:00
|
|
|
|
2019-06-21 18:43:25 +02:00
|
|
|
func main() {
|
|
|
|
app := newApp()
|
2020-04-30 15:16:43 +02:00
|
|
|
app.Logger().SetLevel("debug")
|
|
|
|
|
2020-03-05 21:41:27 +01:00
|
|
|
app.Listen(":8080")
|
2017-06-15 19:02:08 +02:00
|
|
|
}
|