Support for prefixed Orchard Controller API URLs (#355)

* Support for prefixed Orchard Controller API URLs

* Fix Swagger UI

* Remove spurious "fmt" import

* Use url.URL in order to correctly calculate API path for Swagger UI
This commit is contained in:
Nikolay Edigaryev
2025-10-06 20:04:47 +04:00
committed by GitHub
parent 6d23548d81
commit af221cf3c1
7 changed files with 85 additions and 16 deletions
+11 -3
View File
@@ -7,6 +7,7 @@ import (
"fmt"
"net"
"net/http"
"net/url"
"os"
"strings"
"time"
@@ -46,6 +47,7 @@ const (
type Controller struct {
dataDir *DataDir
listenAddr string
apiPrefix string
tlsConfig *tls.Config
listener net.Listener
httpServer *http.Server
@@ -262,11 +264,17 @@ func (controller *Controller) Run(ctx context.Context) error {
func (controller *Controller) Address() string {
hostPort := strings.ReplaceAll(controller.listener.Addr().String(), "[::]", "127.0.0.1")
if controller.tlsConfig != nil {
return fmt.Sprintf("https://%s", hostPort)
url := url.URL{
Scheme: "http",
Host: hostPort,
Path: controller.apiPrefix,
}
return fmt.Sprintf("http://%s", hostPort)
if controller.tlsConfig != nil {
url.Scheme = "https"
}
return url.String()
}
func (controller *Controller) SSHAddress() (string, bool) {