From 505335d872532877df0a15a39528846d0846bac3 Mon Sep 17 00:00:00 2001 From: Vikram Rangnekar Date: Fri, 24 Apr 2020 01:23:35 -0400 Subject: [PATCH] feat: add config to set api endpoint prefix --- internal/serv/api.go | 1 + internal/serv/serv.go | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/internal/serv/api.go b/internal/serv/api.go index bf9ac90..aafdd36 100644 --- a/internal/serv/api.go +++ b/internal/serv/api.go @@ -45,6 +45,7 @@ type Serv struct { MigrationsPath string `mapstructure:"migrations_path"` AllowedOrigins []string `mapstructure:"cors_allowed_origins"` DebugCORS bool `mapstructure:"cors_debug"` + APIPath string `mapstructure:"api_path"` Auth auth.Auth Auths []auth.Auth diff --git a/internal/serv/serv.go b/internal/serv/serv.go index c00a435..5012295 100644 --- a/internal/serv/serv.go +++ b/internal/serv/serv.go @@ -6,6 +6,7 @@ import ( "net/http" "os" "os/signal" + "path" "strings" "time" @@ -111,9 +112,15 @@ func routeHandler() (http.Handler, error) { return mux, nil } + apiRoute := "/api/v1/graphql" + + if len(conf.APIPath) != 0 { + apiRoute = path.Join("/", conf.APIPath, "/v1/graphql") + } + routes := map[string]http.Handler{ - "/health": http.HandlerFunc(health), - "/api/v1/graphql": apiV1Handler(), + "/health": http.HandlerFunc(health), + apiRoute: apiV1Handler(), } if err := setActionRoutes(routes); err != nil {