Skip to content

Commit

Permalink
Refactor port host configuration and added route server context enric…
Browse files Browse the repository at this point in the history
…hment #59
  • Loading branch information
Marcel Ludwig committed Nov 10, 2020
1 parent f8eecc6 commit f86fd47
Show file tree
Hide file tree
Showing 27 changed files with 547 additions and 327 deletions.
15 changes: 0 additions & 15 deletions config/runtime/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,11 @@ package runtime
import (
"os"
"path/filepath"
"strconv"
"time"

"github.com/avenga/couper/config"
)

type Port int

func (p Port) String() string {
return strconv.Itoa(int(p))
}

type Server map[Port]*ServerMux

// ServerMux represents the ServerMux struct.
type ServerMux struct {
Server *config.Server
Mux *MuxOptions
}

// HTTPConfig represents the configuration of the ingress HTTP server.
type HTTPConfig struct {
HealthPath string `env:"health_path"`
Expand Down
57 changes: 2 additions & 55 deletions config/runtime/mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,71 +2,18 @@ package runtime

import (
"net/http"
"path"

"github.com/avenga/couper/config"
"github.com/avenga/couper/errors"
"github.com/avenga/couper/utils"
)

type MuxOptions struct {
APIErrTpl *errors.Template
APIBasePath string
EndpointRoutes map[string]http.Handler
FileBasePath string
FileErrTpl *errors.Template
FileRoutes map[string]http.Handler
ServerErrTpl *errors.Template
SPABasePath string
SPARoutes map[string]http.Handler
}

func NewMuxOptions(conf *config.Server) (*MuxOptions, error) {
options := &MuxOptions{
APIErrTpl: errors.DefaultJSON,
FileErrTpl: errors.DefaultHTML,
ServerErrTpl: errors.DefaultHTML,
func NewMuxOptions() *MuxOptions {
return &MuxOptions{
EndpointRoutes: make(map[string]http.Handler),
FileRoutes: make(map[string]http.Handler),
SPARoutes: make(map[string]http.Handler),
}

if conf.ErrorFile != "" {
tpl, err := errors.NewTemplateFromFile(conf.ErrorFile)
if err != nil {
return nil, err
}
options.ServerErrTpl = tpl
options.FileErrTpl = tpl
}

if conf.API != nil {
options.APIBasePath = path.Join("/", conf.BasePath, conf.API.BasePath)

if conf.API.ErrorFile != "" {
tpl, err := errors.NewTemplateFromFile(conf.API.ErrorFile)
if err != nil {
return nil, err
}
options.APIErrTpl = tpl
}
}

if conf.Files != nil {
if conf.Files.ErrorFile != "" {
tpl, err := errors.NewTemplateFromFile(conf.Files.ErrorFile)
if err != nil {
return nil, err
}
options.FileErrTpl = tpl
}

options.FileBasePath = utils.JoinPath("/", conf.BasePath, conf.Files.BasePath)
}

if conf.Spa != nil {
options.SPABasePath = utils.JoinPath("/", conf.BasePath, conf.Spa.BasePath)
}

return options, nil
}
Loading

0 comments on commit f86fd47

Please sign in to comment.