Add mechanism for bundling UI assets. (#153)

* Add mechanism for bundling UI assets.

The scripts/uigen.sh script will check out the UI repo, build assets,
create a static assets file, and clean up.

The dev Makefile target has been modified to run this script if no
assets file is found. There is also a build-ui target that will
unilaterally update (the dev target only builds if the file isn't found,
but doesn't update).

The handler has been updated to add the default org ID as a header if
the request path is "/".

Co-authored-by: Randall Morey <randall@randallmorey.com>
This commit is contained in:
Jeff MitchellandRandall Morey authored and GitHub committed 2020-06-30 11:26:22 -04:00
1 parent 8d8bb42418
commit 8da4effd5e
10 files changed
+147 -65

No files matched your search

+23
View File
@@ -0,0 +1,23 @@
package ui
import (
"net/http"
"path/filepath"
"github.com/hashicorp/go-hclog"
)
func DevPassthroughHandler(logger hclog.Logger, passthroughDir string) http.Handler {
// Panic may not be ideal but this is never a production call and it'll
// panic on startup. We could also just change the function to return
// an error.
abs, err := filepath.Abs(passthroughDir)
if err != nil {
panic(err)
}
logger.Warn("serving passthrough files at /", "path", abs)
fs := http.FileServer(http.Dir(abs))
prefixHandler := http.StripPrefix("/", fs)
return prefixHandler
}