feat(proxy): Add reverse proxy feature
This commit is contained in:
41
app/server/host.go
Normal file
41
app/server/host.go
Normal file
@@ -0,0 +1,41 @@
|
||||
package server
|
||||
|
||||
import (
|
||||
"net/http/httputil"
|
||||
"net/url"
|
||||
|
||||
"git.secnex.io/secnex/api-gateway/config"
|
||||
)
|
||||
|
||||
type Hosts map[string]*Host
|
||||
|
||||
type Host struct {
|
||||
ID string
|
||||
Name string
|
||||
Domain string
|
||||
proxy *httputil.ReverseProxy
|
||||
}
|
||||
|
||||
func NewHosts(cfg *config.Configuration) Hosts {
|
||||
hosts := make(Hosts)
|
||||
for _, host := range cfg.Hosts {
|
||||
hosts[host.ID] = NewHost(&host)
|
||||
}
|
||||
return hosts
|
||||
}
|
||||
|
||||
func NewHost(host *config.Host) *Host {
|
||||
return &Host{
|
||||
ID: host.ID,
|
||||
Name: host.Name,
|
||||
Domain: host.Domain,
|
||||
proxy: httputil.NewSingleHostReverseProxy(&url.URL{
|
||||
Scheme: "https",
|
||||
Host: host.Domain,
|
||||
}),
|
||||
}
|
||||
}
|
||||
|
||||
func (hs Hosts) GetHost(domain string) *Host {
|
||||
return hs[domain]
|
||||
}
|
||||
Reference in New Issue
Block a user