mirror of
https://github.com/openziti/zrok.git
synced 2024-11-22 08:03:49 +01:00
36 lines
790 B
Go
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
|
|
}
|