Add support for extra header
Signed-off-by: Bryan Frimin <bryan@getprobo.com>
This commit is contained in:
@@ -20,7 +20,8 @@ type (
|
|||||||
}
|
}
|
||||||
|
|
||||||
apiConfig struct {
|
apiConfig struct {
|
||||||
Addr string `json:"addr"`
|
Addr string `json:"addr"`
|
||||||
Cors corsConfig `json:"cors"`
|
Cors corsConfig `json:"cors"`
|
||||||
|
ExtraHeaderFields map[string]string `json:"extra-header-fields"`
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -224,6 +224,7 @@ func (impl *Implm) Run(
|
|||||||
serverHandler, err := server.NewServer(
|
serverHandler, err := server.NewServer(
|
||||||
server.Config{
|
server.Config{
|
||||||
AllowedOrigins: impl.cfg.Api.Cors.AllowedOrigins,
|
AllowedOrigins: impl.cfg.Api.Cors.AllowedOrigins,
|
||||||
|
ExtraHeaderFields: impl.cfg.Api.ExtraHeaderFields,
|
||||||
Probo: proboService,
|
Probo: proboService,
|
||||||
Usrmgr: usrmgrService,
|
Usrmgr: usrmgrService,
|
||||||
ConnectorRegistry: defaultConnectorRegistry,
|
ConnectorRegistry: defaultConnectorRegistry,
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ import (
|
|||||||
// Config holds the configuration for the server
|
// Config holds the configuration for the server
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AllowedOrigins []string
|
AllowedOrigins []string
|
||||||
|
ExtraHeaderFields map[string]string
|
||||||
Probo *probo.Service
|
Probo *probo.Service
|
||||||
Usrmgr *usrmgr.Service
|
Usrmgr *usrmgr.Service
|
||||||
Auth console_v1.AuthConfig
|
Auth console_v1.AuthConfig
|
||||||
@@ -45,9 +46,10 @@ type Config struct {
|
|||||||
|
|
||||||
// Server represents the main server that handles both API and frontend requests
|
// Server represents the main server that handles both API and frontend requests
|
||||||
type Server struct {
|
type Server struct {
|
||||||
apiServer *api.Server
|
apiServer *api.Server
|
||||||
webServer *web.Server
|
webServer *web.Server
|
||||||
router *chi.Mux
|
router *chi.Mux
|
||||||
|
extraHeaderFields map[string]string
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewServer creates a new server instance
|
// NewServer creates a new server instance
|
||||||
@@ -77,9 +79,10 @@ func NewServer(cfg Config) (*Server, error) {
|
|||||||
router := chi.NewRouter()
|
router := chi.NewRouter()
|
||||||
|
|
||||||
server := &Server{
|
server := &Server{
|
||||||
apiServer: apiServer,
|
apiServer: apiServer,
|
||||||
webServer: webServer,
|
webServer: webServer,
|
||||||
router: router,
|
router: router,
|
||||||
|
extraHeaderFields: cfg.ExtraHeaderFields,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set up routes
|
// Set up routes
|
||||||
@@ -106,5 +109,9 @@ func (s *Server) setupRoutes() {
|
|||||||
|
|
||||||
// ServeHTTP implements the http.Handler interface
|
// ServeHTTP implements the http.Handler interface
|
||||||
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
|
for key, value := range s.extraHeaderFields {
|
||||||
|
w.Header().Set(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
s.router.ServeHTTP(w, r)
|
s.router.ServeHTTP(w, r)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user