iris/_examples/file-server/single-page-application/embedded-single-page-application/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

43 lines
1013 B
Go

package main
import (
"github.com/kataras/iris/v12"
)
// $ go get -u github.com/go-bindata/go-bindata/v3/go-bindata
// $ go-bindata -nomemcopy -fs ./public/...
// $ go run .
var page = struct {
Title string
}{"Welcome"}
func newApp() *iris.Application {
app := iris.New()
app.RegisterView(iris.HTML("./public", ".html").Binary(Asset, AssetNames))
app.Get("/", func(ctx iris.Context) {
ctx.ViewData("Page", page)
ctx.View("index.html")
})
// We didn't add a `-prefix "public"` argument on go-bindata command
// because the view's `Assset` and `AssetNames` require fullpath.
// Make use of the `PrefixDir` to serve assets on cases like that;
// when bindata.go file contains files that are
// not necessary public assets to be served.
app.HandleDir("/", iris.PrefixDir("public", AssetFile()))
return app
}
func main() {
app := newApp()
// http://localhost:8080
// http://localhost:8080/app.js
// http://localhost:8080/css/main.css
// http://localhost:8080/app2
app.Listen(":8080")
}