MCPcopy Index your code
hub / github.com/ddev/ddev / GetWebContainerDirectHTTPPort

Method GetWebContainerDirectHTTPPort

pkg/ddevapp/ddevapp.go:3562–3589  ·  view source on GitHub ↗

GetWebContainerDirectHTTPPort returns the direct-access public tcp port for http

()

Source from the content-addressed store, hash-verified

3560
3561// GetWebContainerDirectHTTPPort returns the direct-access public tcp port for http
3562func (app *DdevApp) GetWebContainerDirectHTTPPort() (int, error) {
3563 webContainer, err := app.FindContainerByType("web")
3564 if err != nil || webContainer == nil {
3565 return -1, fmt.Errorf("unable to find web container for app: %s, err %v", app.Name, err)
3566 }
3567
3568 // Try getting the published port for the standard HTTP port first
3569 port, err := app.GetPublishedPortForPrivatePort("web", 80)
3570 if err == nil && port != 0 {
3571 return port, nil
3572 }
3573
3574 // If standard method fails and it's a generic webserver with extra exposed ports
3575 if app.WebserverType == nodeps.WebserverGeneric && len(app.WebExtraExposedPorts) > 0 {
3576 for _, extraPort := range app.WebExtraExposedPorts {
3577 // Check only ports mapped to HTTP (port 80)
3578 if extraPort.HTTPPort == 80 {
3579 containerPort := uint16(extraPort.WebContainerPort)
3580 publishedPort, err := app.GetPublishedPortForPrivatePort("web", containerPort)
3581 if err == nil && publishedPort != 0 {
3582 return publishedPort, nil
3583 }
3584 }
3585 }
3586 }
3587
3588 return -1, fmt.Errorf("no public port found for private port 80")
3589}
3590
3591// GetWebContainerDirectHTTPSPort returns the direct-access public tcp port for https
3592func (app *DdevApp) GetWebContainerDirectHTTPSPort() (int, error) {

Callers 1

Calls 3

FindContainerByTypeMethod · 0.95
ErrorfMethod · 0.80

Tested by

no test coverage detected