Merge pull request #14 from owncloud/http-root

Add custom http root
This commit is contained in:
Thomas Boerger
2019-12-09 16:26:14 +01:00
committed by GitHub
5 changed files with 30 additions and 7 deletions

View File

@@ -71,6 +71,9 @@ GRAPH_DEBUG_ZPAGES
GRAPH_HTTP_ADDR
: Address to bind http server, defaults to `0.0.0.0:9120`
GRAPH_HTTP_ROOT
: Root path of http server, defaults to `/`
##### Health
GRAPH_DEBUG_ADDR
@@ -126,6 +129,9 @@ If you prefer to configure the service with commandline flags you can see the av
--http-addr
: Address to bind http server, defaults to `0.0.0.0:9120`
--http-root
: Root path of http server, defaults to `/`
##### Health
--debug-addr

View File

@@ -4,6 +4,7 @@ import (
"context"
"os"
"os/signal"
"strings"
"time"
"contrib.go.opencensus.io/exporter/jaeger"
@@ -28,6 +29,13 @@ func Server(cfg *config.Config) cli.Command {
Name: "server",
Usage: "Start integrated server",
Flags: flagset.ServerWithConfig(cfg),
Before: func(c *cli.Context) error {
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)

View File

@@ -18,6 +18,7 @@ type Debug struct {
// HTTP defines the available http configuration.
type HTTP struct {
Addr string
Root string
}
// Tracing defines the available tracing configuration.

View File

@@ -120,5 +120,12 @@ func ServerWithConfig(cfg *config.Config) []cli.Flag {
EnvVar: "GRAPH_HTTP_ADDR",
Destination: &cfg.HTTP.Addr,
},
&cli.StringFlag{
Name: "http-root",
Value: "/",
Usage: "Root path of http server",
EnvVar: "GRAPH_HTTP_ROOT",
Destination: &cfg.HTTP.Root,
},
}
}

View File

@@ -27,13 +27,14 @@ func NewService(opts ...Option) Service {
logger: &options.Logger,
}
m.Route("/v1.0", func(r chi.Router) {
r.Get("/me", svc.GetMe)
r.Route("/users", func(r chi.Router) {
r.Get("/", svc.GetUsers)
r.Route("/{userID}", func(r chi.Router) {
r.Use(svc.UserCtx)
r.Get("/", svc.GetUser)
m.Route(options.Config.HTTP.Root, func(r chi.Router) {
r.Route("/v1.0", func(r chi.Router) {
r.Route("/users", func(r chi.Router) {
r.Get("/", svc.GetUsers)
r.Route("/{userID}", func(r chi.Router) {
r.Use(svc.UserCtx)
r.Get("/", svc.GetUser)
})
})
})
})