iris/_examples/file-server/single-page-application/embedded-single-page-application-with-other-routes/main.go
Gerasimos (Makis) Maropoulos c3205dafa1 New DirOptions.Cache field for in-memory caching and pre-compression for the fastest possible static file server
Read HISTORY.md it contains a breaking change, second parameter of HandleDir should be iris.Dir(...) instead of just a string

relative to: https://github.com/kataras/iris/issues/1556#issuecomment-661057446


Former-commit-id: 14b48a06fb3b99287dff543932be2937a64233b9
2020-07-24 13:03:49 +03:00

55 lines
1.4 KiB
Go

package main
import "github.com/kataras/iris/v12"
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go-bindata -fs -prefix "public" ./public/...
// $ go run .
func newApp() *iris.Application {
app := iris.New()
app.OnErrorCode(iris.StatusNotFound, func(ctx iris.Context) {
ctx.Writef("404 not found here")
})
app.HandleDir("/", AssetFile())
// Note:
// if you want a dynamic index page then see the file-server/embedded-single-page-application
// which is registering a view engine based on bindata as well and a root route.
app.Get("/ping", func(ctx iris.Context) {
ctx.WriteString("pong")
})
app.Get("/.well-known", func(ctx iris.Context) {
ctx.WriteString("well-known")
})
app.Get(".well-known/ready", func(ctx iris.Context) {
ctx.WriteString("ready")
})
app.Get(".well-known/live", func(ctx iris.Context) {
ctx.WriteString("live")
})
app.Get(".well-known/metrics", func(ctx iris.Context) {
ctx.Writef("metrics")
})
return app
}
func main() {
app := newApp()
// http://localhost:8080/index.html
// http://localhost:8080/app.js
// http://localhost:8080/css/main.css
//
// http://localhost:8080/ping
// http://localhost:8080/.well-known
// http://localhost:8080/.well-known/ready
// http://localhost:8080/.well-known/live
// http://localhost:8080/.well-known/metrics
//
// Remember: we could use the root wildcard `app.Get("/{param:path}")` and serve the files manually as well.
app.Listen(":8080")
}