feat(proxy): Add reverse proxy feature

This commit is contained in:
Björn Benouarets
2026-02-05 23:58:47 +01:00
parent 07474afae9
commit 30adf0c701
20 changed files with 514 additions and 323 deletions

46
app/server/api.go Normal file
View File

@@ -0,0 +1,46 @@
package server
import (
"net/http"
"git.secnex.io/secnex/api-gateway/config"
)
type Apis map[string]*Api
type Api struct {
ID string
Host *Host
Target *Target
domain string
}
func NewApis(cfg *config.Configuration, hosts Hosts, targets Targets) Apis {
apis := make(Apis)
for _, api := range cfg.Apis {
apis[api.ID] = NewApi(&api, hosts[api.Host], targets[api.Target])
}
return apis
}
func NewApi(api *config.Api, host *Host, target *Target) *Api {
return &Api{
ID: api.ID,
Host: host,
Target: target,
domain: host.Domain,
}
}
func (as Apis) GetApi(domain string) *Api {
for _, api := range as {
if api.domain == domain {
return api
}
}
return nil
}
func (a *Api) ServeHTTP(w http.ResponseWriter, r *http.Request) {
a.Target.proxy.ServeHTTP(w, r)
}