Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions cuhttp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,12 @@ func StartHTTPServer(ctx context.Context, d *deps.Deps, sd *ServiceDeps, dm *sto
chiRouter.Use(corsHeaders)

if cfg.EnableCORS {
chiRouter.Use(handlers.CORS(handlers.AllowedOrigins([]string{"https://" + cfg.DomainName})))
chiRouter.Use(handlers.CORS(handlers.AllowedOrigins([]string{func() string {
if d.Cfg.HTTP.ExternalUrl != "" {
return d.Cfg.HTTP.ExternalUrl
}
return "https://" + d.Cfg.HTTP.DomainName
}()})))
}

// Set up the compression middleware with custom compression levels
Expand Down Expand Up @@ -219,15 +224,15 @@ func StartHTTPServer(ctx context.Context, d *deps.Deps, sd *ServiceDeps, dm *sto

// Start the server with TLS
go func() {
log.Infof("Starting HTTPS server for https://%s on %s", cfg.DomainName, cfg.ListenAddress)
log.Infof("Starting HTTP(S) server for http(s)://%s on %s", cfg.DomainName, cfg.ListenAddress)
var serr error
if !cfg.DelegateTLS {
serr = server.ListenAndServeTLS("", "")
} else {
serr = server.ListenAndServe()
}
if serr != nil {
log.Errorf("Failed to start HTTPS server: %s", serr)
log.Errorf("Failed to start HTTP(S) server: %s", serr)
panic(serr)
}
}()
Expand All @@ -238,7 +243,7 @@ func StartHTTPServer(ctx context.Context, d *deps.Deps, sd *ServiceDeps, dm *sto
if err := server.Shutdown(context.Background()); err != nil {
log.Errorf("shutting down web server failed: %s", err)
}
log.Warn("HTTP Server graceful shutdown successful")
log.Warn("HTTP(S) Server graceful shutdown successful")
}()

return nil
Expand Down
6 changes: 6 additions & 0 deletions deps/config/doc_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions deps/config/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,9 @@ type HTTPConfig struct {
// HTTP and the reverse proxy will handle TLS termination.
DelegateTLS bool

// ExternalUrl is the final URL that external users can access directly.
ExternalUrl string

// ReadTimeout is the maximum duration for reading the entire or next request, including body, from the client.
// Time duration string (e.g., "1h2m3s") in TOML format. (Default: "30m0s")
ReadTimeout time.Duration
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ description: The default curio configuration
# type: bool
#DelegateTLS = false

# ExternalUrl is the final URL that external users can access directly.
#
# type: string
#ExternalUrl = ""

# ReadTimeout is the maximum duration for reading the entire or next request, including body, from the client.
# Time duration string (e.g., "1h2m3s") in TOML format. (Default: "30m0s")
#
Expand Down
9 changes: 7 additions & 2 deletions market/ipni/ipni-provider/ipni-provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,12 +164,17 @@ func NewProvider(d *deps.Deps) (*Provider, error) {
httpServerAddresses := map[string]multiaddr.Multiaddr{}

{
u, err := url.Parse(fmt.Sprintf("https://%s", d.Cfg.HTTP.DomainName))
u, err := url.Parse(func() string {
if d.Cfg.HTTP.ExternalUrl != "" {
return d.Cfg.HTTP.ExternalUrl
}
return fmt.Sprintf("https://%s", d.Cfg.HTTP.DomainName)
}())
if err != nil {
return nil, xerrors.Errorf("parsing announce address domain: %w", err)
}

if build.BuildType != build.BuildMainnet && build.BuildType != build.BuildCalibnet {
if d.Cfg.HTTP.ExternalUrl == "" && build.BuildType != build.BuildMainnet && build.BuildType != build.BuildCalibnet {
ls := strings.Split(d.Cfg.HTTP.ListenAddress, ":")
u, err = url.Parse(fmt.Sprintf("http://%s:%s", d.Cfg.HTTP.DomainName, ls[1]))
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions tasks/indexing/task_ipni.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,16 @@ func (I *IPNITask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (done b
}

{
u, err := url.Parse(fmt.Sprintf("https://%s", I.cfg.HTTP.DomainName))
u, err := url.Parse(func() string {
if I.cfg.HTTP.ExternalUrl != "" {
return I.cfg.HTTP.ExternalUrl
}
return fmt.Sprintf("https://%s", I.cfg.HTTP.DomainName)
}())
if err != nil {
return false, xerrors.Errorf("parsing announce address domain: %w", err)
}
if build.BuildType != build.BuildMainnet && build.BuildType != build.BuildCalibnet {
if I.cfg.HTTP.ExternalUrl == "" && build.BuildType != build.BuildMainnet && build.BuildType != build.BuildCalibnet {
ls := strings.Split(I.cfg.HTTP.ListenAddress, ":")
u, err = url.Parse(fmt.Sprintf("http://%s:%s", I.cfg.HTTP.DomainName, ls[1]))
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions tasks/indexing/task_pdp_ipni.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,16 @@ func (P *PDPIPNITask) Do(taskID harmonytask.TaskID, stillOwned func() bool) (don
}

{
u, err := url.Parse(fmt.Sprintf("https://%s:443", P.cfg.HTTP.DomainName))
u, err := url.Parse(func() string {
if P.cfg.HTTP.ExternalUrl != "" {
return P.cfg.HTTP.ExternalUrl
}
return fmt.Sprintf("https://%s", P.cfg.HTTP.DomainName)
}())
if err != nil {
return false, xerrors.Errorf("parsing announce address domain: %w", err)
}
if build.BuildType != build.BuildMainnet && build.BuildType != build.BuildCalibnet {
if P.cfg.HTTP.ExternalUrl == "" && build.BuildType != build.BuildMainnet && build.BuildType != build.BuildCalibnet {
ls := strings.Split(P.cfg.HTTP.ListenAddress, ":")
u, err = url.Parse(fmt.Sprintf("http://%s:%s", P.cfg.HTTP.DomainName, ls[1]))
if err != nil {
Expand Down
9 changes: 7 additions & 2 deletions tasks/pdp/watch_piece_delete.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,11 +299,16 @@ func processIndexingAndIPNICleanup(ctx context.Context, db *harmonydb.DB, cfg *c
}

{
u, err := url.Parse(fmt.Sprintf("https://%s:443", cfg.DomainName))
u, err := url.Parse(func() string {
if cfg.ExternalUrl != "" {
return cfg.ExternalUrl
}
return fmt.Sprintf("https://%s", cfg.DomainName)
}())
if err != nil {
return false, xerrors.Errorf("parsing announce address domain: %w", err)
}
if build.BuildType != build.BuildMainnet && build.BuildType != build.BuildCalibnet {
if cfg.ExternalUrl == "" && build.BuildType != build.BuildMainnet && build.BuildType != build.BuildCalibnet {
ls := strings.Split(cfg.ListenAddress, ":")
u, err = url.Parse(fmt.Sprintf("http://%s:%s", cfg.DomainName, ls[1]))
if err != nil {
Expand Down
16 changes: 12 additions & 4 deletions web/api/webrpc/pdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,10 +436,18 @@ func (a *WebRPC) FSRegister(ctx context.Context, name, description, location str
return xerrors.Errorf("provider is already registered")
}

serviceURL := url.URL{
Scheme: "https",
Host: a.deps.Cfg.HTTP.DomainName,
}
serviceURL := func() *url.URL {
if a.deps.Cfg.HTTP.ExternalUrl != "" {
u, err := url.Parse(a.deps.Cfg.HTTP.ExternalUrl)
if err == nil {
return u
}
}
return &url.URL{
Scheme: "https",
Host: a.deps.Cfg.HTTP.DomainName,
}
}()

tokenAddress, err := contract.USDFCAddress()
if err != nil {
Expand Down