From 3b7c9738a3f545589ea228c17260cc398b79fb45 Mon Sep 17 00:00:00 2001 From: Brad Rydzewski Date: Sat, 25 Apr 2015 16:16:56 -0700 Subject: [PATCH] ability to squash and embed static files --- .gitignore | 6 +++++- Makefile | 17 ++++++++++++++++- drone.go | 22 ++++++++++++++++++---- queue/plugin/server.go | 2 +- server/static/scripts/term.js | 2 +- 5 files changed, 41 insertions(+), 8 deletions(-) diff --git a/.gitignore b/.gitignore index 8383f7998..bff14d2cf 100644 --- a/.gitignore +++ b/.gitignore @@ -13,5 +13,9 @@ drone.sublime-workspace *.db *.txt *.toml +bindata.go -drone \ No newline at end of file +# combined assets +server/static/drone.js + +drone diff --git a/Makefile b/Makefile index 7a9c3bd0b..986d76600 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,10 @@ SHA := $(shell git rev-parse --short HEAD) VERSION := 0.4.0-alpha -all: build +all: concat bindata build deps: + go get -u github.com/jteeuwen/go-bindata/... go get -t -v ./... test: @@ -16,3 +17,17 @@ build: clean: find . -name "*.out" -delete rm -f drone + rm -f bindata.go + +concat: + cat server/static/scripts/drone.js \ + server/static/scripts/services/*.js \ + server/static/scripts/filters/*.js \ + server/static/scripts/controllers/*.js \ + server/static/scripts/term.js > server/static/drone.js + +bindata_debug: + go-bindata --debug server/static/... + +bindata: + go-bindata server/static/... \ No newline at end of file diff --git a/drone.go b/drone.go index 7083c5ea9..50cba8c7a 100644 --- a/drone.go +++ b/drone.go @@ -2,6 +2,7 @@ package main import ( "flag" + "net/http" "github.com/gin-gonic/gin" @@ -11,16 +12,17 @@ import ( "github.com/drone/drone/server" "github.com/drone/drone/server/session" "github.com/drone/drone/settings" + "github.com/elazarl/go-bindata-assetfs" queue "github.com/drone/drone/queue/builtin" ) -var path = flag.String("config", "drone.toml", "") +var conf = flag.String("config", "drone.toml", "") func main() { flag.Parse() - settings, err := settings.Parse(*path) + settings, err := settings.Parse(*conf) if err != nil { panic(err) } @@ -134,6 +136,18 @@ func main() { r.NoRoute(func(c *gin.Context) { c.File("server/static/index.html") }) - r.Static("/static", "server/static") - r.Run(settings.Server.Addr) + + http.Handle("/static/", static()) + http.Handle("/", r) + http.ListenAndServe(settings.Server.Addr, nil) +} + +// static is a helper function that will setup handlers +// for serving static files. +func static() http.Handler { + return http.StripPrefix("/static/", http.FileServer(&assetfs.AssetFS{ + Asset: Asset, + AssetDir: AssetDir, + Prefix: "server/static", + })) } diff --git a/queue/plugin/server.go b/queue/plugin/server.go index baf355072..bab3b931c 100644 --- a/queue/plugin/server.go +++ b/queue/plugin/server.go @@ -72,7 +72,7 @@ func remove(c *gin.Context) { func pull(c *gin.Context) { q := fromContext(c) var work *queue.Work - if c.Request.FormValue("ack") != "" { + if c.Request.FormValue("ack") == "true" { work = q.PullAck() } else { work = q.Pull() diff --git a/server/static/scripts/term.js b/server/static/scripts/term.js index 925e463a1..0e925abad 100644 --- a/server/static/scripts/term.js +++ b/server/static/scripts/term.js @@ -387,4 +387,4 @@ Filter = (function() { return Filter; -})(); \ No newline at end of file +})();