This commit is contained in:
@@ -22,6 +22,7 @@ var staticFiles embed.FS
|
||||
type gateway struct {
|
||||
core *url.URL
|
||||
continuity *url.URL
|
||||
commit *url.URL
|
||||
client *http.Client
|
||||
static http.Handler
|
||||
}
|
||||
@@ -31,9 +32,10 @@ type routeTarget uint8
|
||||
const (
|
||||
targetCore routeTarget = iota
|
||||
targetContinuity
|
||||
targetCommit
|
||||
)
|
||||
|
||||
func newHandler(coreURL, continuityURL string, client *http.Client) (http.Handler, error) {
|
||||
func newHandler(coreURL, continuityURL, commitURL string, client *http.Client) (http.Handler, error) {
|
||||
core, err := parseRuntimeURL(coreURL, "Core")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
@@ -42,6 +44,10 @@ func newHandler(coreURL, continuityURL string, client *http.Client) (http.Handle
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
commit, err := parseRuntimeURL(commitURL, "Commit")
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
assets, err := fs.Sub(staticFiles, "static")
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("load embedded console: %w", err)
|
||||
@@ -49,7 +55,7 @@ func newHandler(coreURL, continuityURL string, client *http.Client) (http.Handle
|
||||
if client == nil {
|
||||
client = http.DefaultClient
|
||||
}
|
||||
return securityHeaders(&gateway{core: core, continuity: continuity, client: client, static: http.FileServer(http.FS(assets))}), nil
|
||||
return securityHeaders(&gateway{core: core, continuity: continuity, commit: commit, client: client, static: http.FileServer(http.FS(assets))}), nil
|
||||
}
|
||||
|
||||
func parseRuntimeURL(rawURL, name string) (*url.URL, error) {
|
||||
@@ -98,6 +104,8 @@ func (g *gateway) forwardAPI(w http.ResponseWriter, r *http.Request) {
|
||||
upstream := g.core
|
||||
if routeTarget == targetContinuity {
|
||||
upstream = g.continuity
|
||||
} else if routeTarget == targetCommit {
|
||||
upstream = g.commit
|
||||
}
|
||||
target := *upstream
|
||||
target.Path = upstreamPath
|
||||
@@ -147,6 +155,13 @@ func creatorRoute(method, path string) (routeTarget, string, bool) {
|
||||
}
|
||||
case method == http.MethodGet && path == "/api/prospective-items":
|
||||
return targetContinuity, "/v1/creator/prospective-items", true
|
||||
case method == http.MethodPost && path == "/api/actions/satisfy-delivered":
|
||||
return targetCommit, "/v1/creator/continuity/satisfy-delivered", true
|
||||
case method == http.MethodPost && strings.HasPrefix(path, "/api/actions/") && strings.HasSuffix(path, "/reconcile"):
|
||||
id := strings.TrimSuffix(strings.TrimPrefix(path, "/api/actions/"), "/reconcile")
|
||||
if validID(id) {
|
||||
return targetCommit, "/v1/creator/authorized-actions/" + id + "/reconcile", true
|
||||
}
|
||||
}
|
||||
return targetCore, "", false
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user