-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor routing to use paths generated from hosts #59
Simplified some things
- Loading branch information
Marcel Ludwig
committed
Oct 26, 2020
1 parent
c934719
commit 1d64bec
Showing
15 changed files
with
282 additions
and
697 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,63 @@ | ||
package runtime | ||
|
||
import ( | ||
"net/http" | ||
"path/filepath" | ||
"strings" | ||
|
||
"github.com/avenga/couper/config" | ||
"github.com/avenga/couper/errors" | ||
"github.com/avenga/couper/handler" | ||
"github.com/avenga/couper/utils" | ||
) | ||
|
||
// Mux represents a Mux object. | ||
type Mux struct { | ||
API Routes | ||
APIPath string | ||
APIErrTpl *errors.Template | ||
FS Routes | ||
FSPath string | ||
FSErrTpl *errors.Template | ||
SPA Routes | ||
SPAPath string | ||
type MuxOptions struct { | ||
APIErrTpl *errors.Template | ||
APIPath string | ||
EndpointRoutes map[string]http.Handler | ||
FileHandler http.Handler | ||
FileErrTpl *errors.Template | ||
SPARoutes map[string]http.Handler | ||
} | ||
|
||
func NewMuxOptions(conf *config.Server) (*MuxOptions, error) { | ||
options := &MuxOptions{ | ||
APIErrTpl: errors.DefaultJSON, | ||
FileErrTpl: errors.DefaultHTML, | ||
EndpointRoutes: make(map[string]http.Handler), | ||
SPARoutes: make(map[string]http.Handler), | ||
} | ||
|
||
if conf.API != nil { | ||
options.APIPath = utils.JoinPath("/", conf.BasePath, conf.API.BasePath) | ||
for strings.HasSuffix(options.APIPath, "/") { | ||
options.APIPath = options.APIPath[:len(options.APIPath)-1] | ||
} | ||
|
||
if conf.API.ErrorFile != "" { | ||
tpl, err := errors.NewTemplateFromFile(conf.Files.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 | ||
} | ||
|
||
absPath, err := filepath.Abs(conf.Files.DocumentRoot) | ||
if err != nil { | ||
return nil, err | ||
} | ||
options.FileHandler = handler.NewFile(conf.Files.BasePath, absPath, options.FileErrTpl) | ||
} | ||
|
||
return options, nil | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.