From 712c18459f2ded422723337f98a06e47c8234bfc Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 25 Apr 2015 16:43:51 -0700 Subject: [PATCH] serving the index.html page from bindata --- drone.go | 12 +++++++++++- server/server.go | 4 ++-- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/drone.go b/drone.go index 50cba8c7a..cca4dc82b 100644 --- a/drone.go +++ b/drone.go @@ -2,6 +2,7 @@ package main import ( "flag" + "html/template" "net/http" "github.com/gin-gonic/gin" @@ -133,8 +134,9 @@ func main() { auth.POST("", server.GetLogin) } + r.SetHTMLTemplate(index()) r.NoRoute(func(c *gin.Context) { - c.File("server/static/index.html") + c.HTML(200, "index.html", nil) }) http.Handle("/static/", static()) @@ -151,3 +153,11 @@ func static() http.Handler { Prefix: "server/static", })) } + +// index is a helper function that will setup a template +// for rendering the main angular index.html file. +func index() *template.Template { + file := MustAsset("server/static/index.html") + filestr := string(file) + return template.Must(template.New("index.html").Parse(filestr)) +} diff --git a/server/server.go b/server/server.go index 55ef51d2f..ce96d4c43 100644 --- a/server/server.go +++ b/server/server.go @@ -164,10 +164,10 @@ func SetRepo() gin.HandlerFunc { r, err := ds.Repo(owner + "/" + name) switch { case err != nil && u != nil: - c.Fail(401, err) + c.Fail(404, err) return case err != nil && u == nil: - c.Fail(404, err) + c.Fail(401, err) return } c.Set("repo", r)