-
Notifications
You must be signed in to change notification settings - Fork 247
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2246 from target/remove-dev-proxy
dev: replace webpack-dev-server with watch
- Loading branch information
Showing
16 changed files
with
456 additions
and
1,089 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
build: while true; do make -qs bin/goalert || make bin/goalert || (echo '\033[0;31mBuild Failure'; sleep 3); sleep 0.1; done | ||
|
||
@watch-file=./bin/goalert | ||
goalert: ./bin/goalert -l=localhost:3030 --ui-url=http://localhost:3035 --db-url=postgres://goalert@localhost:5432/goalert?sslmode=disable --listen-sysapi=localhost:1234 --listen-prometheus=localhost:2112 | ||
goalert: ./bin/goalert -l=localhost:3030 --ui-dir=web/src/build --db-url=postgres://goalert@localhost:5432/goalert?sslmode=disable --listen-sysapi=localhost:1234 --listen-prometheus=localhost:2112 | ||
|
||
smtp: go run github.com/mailhog/MailHog -ui-bind-addr=localhost:8025 -api-bind-addr=localhost:8025 -smtp-bind-addr=localhost:1025 | grep -v KEEPALIVE | ||
prom: bin/tools/prometheus --log.level=warn --config.file=devtools/prometheus/prometheus.yml --storage.tsdb.path=bin/prom-data/ --web.listen-address=localhost:9090 | ||
|
||
@watch-file=./web/src/webpack.config.js | ||
ui: yarn workspace goalert-web webpack serve --config ./webpack.config.js | ||
ui: yarn workspace goalert-web webpack --config ./webpack.config.js --watch |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
package web | ||
|
||
import ( | ||
"crypto/sha256" | ||
"encoding/hex" | ||
"io" | ||
"net/http" | ||
"sync" | ||
) | ||
|
||
type etagHandler struct { | ||
tags map[string]string | ||
h http.Handler | ||
fs http.FileSystem | ||
mx sync.Mutex | ||
static bool | ||
} | ||
|
||
func NewEtagFileServer(files http.FileSystem, static bool) http.Handler { | ||
return &etagHandler{ | ||
tags: make(map[string]string), | ||
h: http.FileServer(files), | ||
fs: files, | ||
static: static, | ||
} | ||
} | ||
|
||
func (e *etagHandler) etag(name string) string { | ||
e.mx.Lock() | ||
defer e.mx.Unlock() | ||
|
||
if tag, ok := e.tags[name]; e.static && ok { | ||
return tag | ||
} | ||
|
||
f, err := e.fs.Open(name) | ||
if err != nil { | ||
e.tags[name] = "" | ||
return "" | ||
} | ||
defer f.Close() | ||
|
||
h := sha256.New() | ||
|
||
_, err = io.Copy(h, f) | ||
if err != nil { | ||
e.tags[name] = "" | ||
return "" | ||
} | ||
|
||
tag := `W/"` + hex.EncodeToString(h.Sum(nil)) + `"` | ||
e.tags[name] = tag | ||
return tag | ||
} | ||
|
||
func (e *etagHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { | ||
if tag := e.etag(req.URL.Path); tag != "" { | ||
w.Header().Set("Cache-Control", "public; max-age=60, stale-while-revalidate=600, stale-if-error=259200") | ||
w.Header().Set("ETag", tag) | ||
} | ||
|
||
e.h.ServeHTTP(w, req) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.