Merge pull request #95 from notzippy/autorun

Made develop mode autorun on start
This commit is contained in:
notzippy
2017-08-03 20:00:26 -07:00
committed by GitHub

View File

@@ -32,7 +32,6 @@ import (
) )
var ( var (
watcher *revel.Watcher
doNotWatch = []string{"tmp", "views", "routes"} doNotWatch = []string{"tmp", "views", "routes"}
lastRequestHadError int32 lastRequestHadError int32
@@ -45,6 +44,7 @@ type Harness struct {
serverHost string serverHost string
port int port int
proxy *httputil.ReverseProxy proxy *httputil.ReverseProxy
watcher *revel.Watcher
} }
func renderError(iw http.ResponseWriter, ir *http.Request, err error) { func renderError(iw http.ResponseWriter, ir *http.Request, err error) {
@@ -63,14 +63,21 @@ func (h *Harness) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return return
} }
// Flush any change events and rebuild app if necessary. // If app did not start when harness was run then trigger the build to capture the error
// Render an error page if the rebuild / restart failed. if h.app == nil {
err := watcher.Notify() // Flush any change events and rebuild app if necessary.
if err != nil { // Render an error page if the rebuild / restart failed.
atomic.CompareAndSwapInt32(&lastRequestHadError, 0, 1) err := h.watcher.Notify()
renderError(w, r, err) if err != nil {
return // In a thread safe manner update the flag so that a request for
// /favicon.ico does not trigger a rebuild
atomic.CompareAndSwapInt32(&lastRequestHadError, 0, 1)
renderError(w, r, err)
return
}
} }
// In a thread safe manner update the flag so that a request for
// /favicon.ico is allowed
atomic.CompareAndSwapInt32(&lastRequestHadError, 1, 0) atomic.CompareAndSwapInt32(&lastRequestHadError, 1, 0)
// Reverse proxy the request. // Reverse proxy the request.
@@ -169,8 +176,9 @@ func (h *Harness) Run() {
paths = append(paths, gopaths...) paths = append(paths, gopaths...)
} }
paths = append(paths, revel.CodePaths...) paths = append(paths, revel.CodePaths...)
watcher = revel.NewWatcher() h.watcher = revel.NewWatcher()
watcher.Listen(h, paths...) h.watcher.Listen(h, paths...)
h.watcher.Notify()
go func() { go func() {
addr := fmt.Sprintf("%s:%d", revel.HTTPAddr, revel.HTTPPort) addr := fmt.Sprintf("%s:%d", revel.HTTPAddr, revel.HTTPPort)