Add a passthrough directory feature. (#76)
This is only compiled in when a `dev` build tag is specified (see #75) for safety. Attempting to use the flag without that tag at build time will fail. However, it is always available within the codebase itself so that tests can be written against this functionality in a programmatic way. Manual testing was performed; no plans to add automated ones as this isn't production-necessary nor exported functionality.
This commit is contained in:
1 parent
9fd86faf15
commit
374a3991a2
7 files changed
+88
-30
No files matched your search
@@ -5,6 +5,7 @@ import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"path"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -30,6 +31,20 @@ func (c *Controller) handler(props HandlerProperties) http.Handler {
|
||||
// Create the muxer to handle the actual endpoints
|
||||
mux := http.NewServeMux()
|
||||
|
||||
if c.conf.RawConfig.PassthroughDirectory != "" {
|
||||
// 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(c.conf.RawConfig.PassthroughDirectory)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
c.logger.Warn("serving passthrough files at /passthrough", "path", abs)
|
||||
fs := http.FileServer(http.Dir(abs))
|
||||
prefixHandler := http.StripPrefix("/passthrough/", fs)
|
||||
mux.Handle("/passthrough/", prefixHandler)
|
||||
}
|
||||
|
||||
mux.Handle("/v1/", handleGrpcGateway(c))
|
||||
|
||||
corsWrappedHandler := wrapHandlerWithCors(mux, props)
|
||||
|
||||
Reference in new issue
Block a user