mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
serving the index.html page from bindata
This commit is contained in:
parent
3b7c9738a3
commit
712c18459f
2 changed files with 13 additions and 3 deletions
12
drone.go
12
drone.go
|
@ -2,6 +2,7 @@ package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"flag"
|
"flag"
|
||||||
|
"html/template"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
@ -133,8 +134,9 @@ func main() {
|
||||||
auth.POST("", server.GetLogin)
|
auth.POST("", server.GetLogin)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
r.SetHTMLTemplate(index())
|
||||||
r.NoRoute(func(c *gin.Context) {
|
r.NoRoute(func(c *gin.Context) {
|
||||||
c.File("server/static/index.html")
|
c.HTML(200, "index.html", nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
http.Handle("/static/", static())
|
http.Handle("/static/", static())
|
||||||
|
@ -151,3 +153,11 @@ func static() http.Handler {
|
||||||
Prefix: "server/static",
|
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))
|
||||||
|
}
|
||||||
|
|
|
@ -164,10 +164,10 @@ func SetRepo() gin.HandlerFunc {
|
||||||
r, err := ds.Repo(owner + "/" + name)
|
r, err := ds.Repo(owner + "/" + name)
|
||||||
switch {
|
switch {
|
||||||
case err != nil && u != nil:
|
case err != nil && u != nil:
|
||||||
c.Fail(401, err)
|
c.Fail(404, err)
|
||||||
return
|
return
|
||||||
case err != nil && u == nil:
|
case err != nil && u == nil:
|
||||||
c.Fail(404, err)
|
c.Fail(401, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
c.Set("repo", r)
|
c.Set("repo", r)
|
||||||
|
|
Loading…
Reference in a new issue