diff --git a/uigo/serve.go b/uigo/serve.go new file mode 100644 index 0000000..4df28b0 --- /dev/null +++ b/uigo/serve.go @@ -0,0 +1,26 @@ +package uigo + +import ( + "github.com/gobuffalo/packr" + "github.com/gin-gonic/gin" + "net/http" +) + +var box = packr.NewBox("../ui/build") + +// Register registers the ui on the root path. +func Register(r *gin.Engine) { + r.GET("/", serveFile("index.html", "text/html")) + r.GET("/index.html", serveFile("index.html", "text/html")) + r.GET("/manifest.json", serveFile("manifest.json", "application/json")) + r.GET("/service-worker.js", serveFile("service-worker.js", "text/javascript")) + r.GET("/assets-manifest.json", serveFile("asserts-manifest.json", "application/json")) + r.GET("/static/*any", gin.WrapH(http.FileServer(box))) +} + +func serveFile(name, contentType string) gin.HandlerFunc { + return func(ctx *gin.Context) { + ctx.Header("Content-Type", contentType) + ctx.String(200, box.String(name)) + } +}