zrok/http/http.go
2022-07-21 16:01:39 -04:00

36 lines
790 B
Go

package http
import (
"github.com/openziti-test-kitchen/zrok/util"
"github.com/openziti/sdk-golang/ziti"
"github.com/openziti/sdk-golang/ziti/config"
"github.com/pkg/errors"
"net/http"
"time"
)
func Run(cfg *Config) error {
options := ziti.ListenOptions{
ConnectTimeout: 5 * time.Minute,
MaxConnections: 64,
}
zcfg, err := config.NewFromFile(cfg.IdentityPath)
if err != nil {
return errors.Wrap(err, "error loading config")
}
listener, err := ziti.NewContextWithConfig(zcfg).ListenWithOptions("zrok", &options)
if err != nil {
return errors.Wrap(err, "error listening")
}
proxy, err := util.NewProxy("http://localhost:3000")
if err != nil {
return err
}
if err := http.Serve(listener, util.NewProxyHandler(proxy)); err != nil {
return err
}
return nil
}