Merge pull request #56 from influxdata/feature/static-assets

Add simple static asset packaging.
pull/10616/head
Chris Goller 2016-09-16 13:55:23 -05:00 committed by GitHub
commit 5f99983e57
4 changed files with 36 additions and 8 deletions

4
.gitignore vendored
View File

@ -1,3 +1,5 @@
dist/
dist/*.js
dist/*.html
.pull-request
node_modules
mrfusion

View File

@ -17,9 +17,16 @@ docker-${BINARY}: $(SOURCES)
CGO_ENABLED=0 GOOS=linux go build -installsuffix cgo -o ${BINARY} ${LDFLAGS} \
./cmd/mr-fusion-server/main.go
prepare:
assets:
mkdir -p ui/build
go-bindata -o ui/ui.go -ignore 'map|go' -pkg ui -nocompress=true ui/build/...
dev:
go get github.com/sparrc/gdm
gdm restore
go get -u github.com/jteeuwen/go-bindata/...
prepare: dev assets
clean:
if [ -f ${BINARY} ] ; then rm ${BINARY} ; fi

View File

@ -1,7 +1,5 @@
---
machine:
services:
- docker
post:
- go version
- go version | grep 1.7.1 || (sudo rm -rf /usr/local/go && wget https://storage.googleapis.com/golang/go1.7.1.linux-amd64.tar.gz && sudo tar -C /usr/local -xzf go1.7.1.linux-amd64.tar.gz)
@ -13,8 +11,6 @@ dependencies:
- mkdir -p ${HOME}/.go_workspace/src/github.com/influxdata
- ln -sf ${HOME}/mrfusion ${HOME}/.go_workspace/src/github.com/influxdata
- cd ${HOME}/.go_workspace/src/github.com/influxdata/mrfusion && make
override:
- docker info
test:
override:

View File

@ -2,7 +2,10 @@ package restapi
import (
"crypto/tls"
"fmt"
"log"
"net/http"
"strings"
errors "github.com/go-openapi/errors"
runtime "github.com/go-openapi/runtime"
@ -11,6 +14,7 @@ import (
"github.com/influxdata/mrfusion/mock"
"github.com/influxdata/mrfusion/restapi/operations"
"github.com/influxdata/mrfusion/ui"
)
// This file is safe to edit. Once it exists it will not be overwritten
@ -125,7 +129,8 @@ func configureAPI(api *operations.MrFusionAPI) http.Handler {
api.ServerShutdown = func() {}
return setupGlobalMiddleware(api.Serve(setupMiddlewares))
handler := setupGlobalMiddleware(api.Serve(setupMiddlewares))
return handler
}
// The TLS configuration before HTTPS server starts.
@ -142,5 +147,23 @@ func setupMiddlewares(handler http.Handler) http.Handler {
// The middleware configuration happens before anything, this middleware also applies to serving the swagger.json document.
// So this is a good place to plug in a panic handling middleware, logging and metrics
func setupGlobalMiddleware(handler http.Handler) http.Handler {
return handler
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s %s\n", r.RemoteAddr, r.Method, r.URL)
if strings.Contains(r.URL.Path, "/chronograf/v1") {
handler.ServeHTTP(w, r)
return
} else if r.URL.Path == "/ui/build/" {
octets, _ := ui.Asset("ui/build/index.html")
fmt.Fprintf(w, "%s", string(octets))
return
} else if strings.Index(r.URL.Path, "/ui/build/") == 0 {
octets, err := ui.Asset(r.URL.Path[1:])
if err != nil {
http.NotFound(w, r)
}
fmt.Fprintf(w, "%s", string(octets))
return
}
http.Redirect(w, r, "/ui/build/index.html", http.StatusFound)
})
}