72 lines
1.9 KiB
Go
72 lines
1.9 KiB
Go
/*
|
|
Example:
|
|
|
|
rp1 := reverseproxy.New(ctx, "http://localhost:8080")
|
|
rp2 := reverseproxy.New(ctx, "http://localhost:3001")
|
|
rp3 := reverseproxy.New(ctx, "http://localhost:3002")
|
|
router := router.NewRouter()
|
|
pr1 := router.NewHostRouter("keycloak.z.com")
|
|
pr1.Handler(rp1)
|
|
|
|
go func() {
|
|
s := server.New().Name("proxy1").Port(443).Router(router)
|
|
s.CertKey(CERTS_PATH, "z.com.cert.pem", "z.com.key.pem")
|
|
err := s.ListenAndServeTLS()
|
|
if err != nil {
|
|
log.Println(err.Error())
|
|
}
|
|
}()
|
|
*/
|
|
package main
|
|
|
|
import (
|
|
"github.com/zeevdiukman/go-helper"
|
|
"github.com/zeevdiukman/go-zgate"
|
|
)
|
|
|
|
// main is the entry point of the z application.
|
|
// It initializes and configures the application, sets up entry points,
|
|
// configures routers, and starts the servers. It also starts test HTTP servers
|
|
// for demonstration purposes.
|
|
func main() {
|
|
helper.AppRunner(true, func() {
|
|
|
|
helper.Clear()
|
|
|
|
zGate := zgate.New()
|
|
zGate.BuildActiveEntryPoints()
|
|
zGate.BuildRouters()
|
|
zGate.ListenAndServe()
|
|
|
|
helper.StartTestHTTPServer(3001, "app1")
|
|
helper.StartTestHTTPServer(3002, "app2")
|
|
})
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
func main() {
|
|
Test()
|
|
}
|
|
func Test() {
|
|
ctx := context.Background()
|
|
conf := config.New()
|
|
rp1 := reverseproxy.New(ctx, conf.HTTP.Services["keycloak"].URL)
|
|
rp2 := reverseproxy.New(ctx, conf.HTTP.Services["app1"].URL)
|
|
rp3 := reverseproxy.New(ctx, conf.HTTP.Services["app2"].URL)
|
|
|
|
r := router.NewRouter()
|
|
r.NewDomainRouter(conf.HTTP.Routers["keycloak"].Rules.Map["Domain"].Value).Handler(rp1)
|
|
r.NewDomainRouter(conf.HTTP.Routers["app1"].Rules.Map["Domain"].Value).Handler(rp2)
|
|
r.NewDomainRouter(conf.HTTP.Routers["app2"].Rules.Map["Domain"].Value).Handler(rp3)
|
|
|
|
s := server.New().Name("proxy1").Port(443).Router(r)
|
|
s.CertKey(zgate.CERTS_PATH, "z.com.cert.pem", "z.com.key.pem")
|
|
go s.ListenAndServeTLS()
|
|
helper.StartTestHTTPServer(3001, "app1")
|
|
helper.StartTestHTTPServer(3002, "app2")
|
|
select {}
|
|
}
|
|
|
|
*/
|