Files
threshold/internal/ui/passthrough.go
T
Jeff MitchellandRandall Morey 8da4effd5e 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>
2020-06-30 11:26:22 -04:00

24 lines
573 B
Go

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
}