config: add static file root

This commit is contained in:
Oliver Gugger
2019-10-18 15:10:13 +02:00
parent a44e9fbd22
commit c8cbeb9ab1
5 changed files with 13 additions and 4 deletions

View File

@@ -22,6 +22,10 @@ type config struct {
// to listen for requests. // to listen for requests.
ListenAddr string `long:"listenaddr" description:"The interface we should listen on for client requests"` ListenAddr string `long:"listenaddr" description:"The interface we should listen on for client requests"`
// StaticRoot is the folder where the static content served by the proxy
// is located.
StaticRoot string `long:"staticroot" description:"The folder where the static content is located."`
Authenticator *auth.Config `long:"authenticator" description:"Configuration for the authenticator."` Authenticator *auth.Config `long:"authenticator" description:"Configuration for the authenticator."`
// Services is a list of JSON objects in string format, which specify // Services is a list of JSON objects in string format, which specify

View File

@@ -42,7 +42,9 @@ func start() error {
if err != nil { if err != nil {
return err return err
} }
servicesProxy, err := proxy.New(authenticator, cfg.Services) servicesProxy, err := proxy.New(
authenticator, cfg.Services, cfg.StaticRoot,
)
if err != nil { if err != nil {
return err return err
} }

View File

@@ -35,7 +35,9 @@ type Proxy struct {
// New returns a new Proxy instance that proxies between the services specified, // New returns a new Proxy instance that proxies between the services specified,
// using the auth to validate each request's headers and get new challenge // using the auth to validate each request's headers and get new challenge
// headers if necessary. // headers if necessary.
func New(auth auth.Authenticator, services []*Service) (*Proxy, error) { func New(auth auth.Authenticator, services []*Service, staticRoot string) (
*Proxy, error) {
err := prepareServices(services) err := prepareServices(services)
if err != nil { if err != nil {
return nil, err return nil, err
@@ -68,7 +70,7 @@ func New(auth auth.Authenticator, services []*Service) (*Proxy, error) {
FlushInterval: -1, FlushInterval: -1,
} }
staticServer := http.FileServer(http.Dir("static")) staticServer := http.FileServer(http.Dir(staticRoot))
return &Proxy{ return &Proxy{
server: grpcProxy, server: grpcProxy,

View File

@@ -30,7 +30,7 @@ func TestProxy(t *testing.T) {
}} }}
auth := auth.NewMockAuthenticator() auth := auth.NewMockAuthenticator()
proxy, err := proxy.New(auth, services) proxy, err := proxy.New(auth, services, "static")
if err != nil { if err != nil {
t.Fatalf("failed to create new proxy: %v", err) t.Fatalf("failed to create new proxy: %v", err)
} }

View File

@@ -1,4 +1,5 @@
listenaddr: "localhost:8081" listenaddr: "localhost:8081"
staticroot: "./static"
debuglevel: "debug" debuglevel: "debug"
services: services: