mirror of
https://github.com/kataras/iris.git
synced 2025-12-18 02:17:05 +00:00
DirOptions.PushTargets: add example for https://github.com/kataras/iris/issues/1562
Former-commit-id: 940f07fdb1184266dc315441fb91afa5754092fa
This commit is contained in:
44
_examples/file-server/http2push-embedded-gzipped/main.go
Normal file
44
_examples/file-server/http2push-embedded-gzipped/main.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"github.com/kataras/iris/v12"
|
||||
)
|
||||
|
||||
// Follow the steps below:
|
||||
// $ go get -u github.com/kataras/bindata/cmd/bindata
|
||||
//
|
||||
// $ bindata -prefix "../http2push/" ../http2push/assets/...
|
||||
// # OR if the ./assets directory was inside this example foder:
|
||||
// # bindata ./assets/...
|
||||
//
|
||||
// $ go run .
|
||||
// Physical files are not used, you can delete the "assets" folder and run the example.
|
||||
|
||||
var opts = iris.DirOptions{
|
||||
IndexName: "/index.html",
|
||||
PushTargets: map[string][]string{
|
||||
"/": {
|
||||
"/public/favicon.ico",
|
||||
"/public/js/main.js",
|
||||
"/public/css/main.css",
|
||||
},
|
||||
},
|
||||
Compress: false, // SHOULD be set to false, files already compressed.
|
||||
ShowList: true,
|
||||
Asset: GzipAsset,
|
||||
AssetInfo: GzipAssetInfo,
|
||||
AssetNames: GzipAssetNames,
|
||||
// Required for pre-compressed files:
|
||||
AssetValidator: func(ctx iris.Context, _ string) bool {
|
||||
ctx.Header("Vary", "Content-Encoding")
|
||||
ctx.Header("Content-Encoding", "gzip")
|
||||
return true
|
||||
},
|
||||
}
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
app.HandleDir("/public", "./assets", opts)
|
||||
|
||||
app.Run(iris.TLS(":443", "../http2push/mycert.crt", "../http2push/mykey.key"))
|
||||
}
|
||||
Reference in New Issue
Block a user