Register registers the ui on the root path.
(r *gin.Engine, version model.VersionInfo, register bool)
| 22 | |
| 23 | // Register registers the ui on the root path. |
| 24 | func Register(r *gin.Engine, version model.VersionInfo, register bool) { |
| 25 | uiConfigBytes, err := json.Marshal(uiConfig{Version: version, Register: register}) |
| 26 | if err != nil { |
| 27 | panic(err) |
| 28 | } |
| 29 | |
| 30 | replaceConfig := func(content string) string { |
| 31 | return strings.Replace(content, "%CONFIG%", string(uiConfigBytes), 1) |
| 32 | } |
| 33 | |
| 34 | ui := r.Group("/", gzip.Gzip(gzip.DefaultCompression)) |
| 35 | ui.GET("/", serveFile("index.html", "text/html", replaceConfig)) |
| 36 | ui.GET("/index.html", serveFile("index.html", "text/html", replaceConfig)) |
| 37 | ui.GET("/manifest.json", serveFile("manifest.json", "application/json", noop)) |
| 38 | |
| 39 | subBox, err := fs.Sub(box, "build") |
| 40 | if err != nil { |
| 41 | panic(err) |
| 42 | } |
| 43 | ui.GET("/static/*any", gin.WrapH(http.FileServer(http.FS(subBox)))) |
| 44 | } |
| 45 | |
| 46 | func noop(s string) string { |
| 47 | return s |