Fix broken path prefix
This commit is contained in:
parent
3455a89fd5
commit
46935a7a12
@ -3,7 +3,6 @@ package api
|
|||||||
import (
|
import (
|
||||||
"encoding/base64"
|
"encoding/base64"
|
||||||
"fmt"
|
"fmt"
|
||||||
"github.com/sosedoff/pgweb/static"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
neturl "net/url"
|
neturl "net/url"
|
||||||
"regexp"
|
"regexp"
|
||||||
@ -18,6 +17,7 @@ import (
|
|||||||
"github.com/sosedoff/pgweb/pkg/command"
|
"github.com/sosedoff/pgweb/pkg/command"
|
||||||
"github.com/sosedoff/pgweb/pkg/connection"
|
"github.com/sosedoff/pgweb/pkg/connection"
|
||||||
"github.com/sosedoff/pgweb/pkg/shared"
|
"github.com/sosedoff/pgweb/pkg/shared"
|
||||||
|
"github.com/sosedoff/pgweb/static"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
@ -58,12 +58,20 @@ func setClient(c *gin.Context, newClient *client.Client) error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetHome renderes the home page
|
// GetHome renderes the home page
|
||||||
func GetHome() http.Handler {
|
func GetHome(prefix string) http.Handler {
|
||||||
return http.FileServer(http.FS(static.Static))
|
if prefix != "" {
|
||||||
|
prefix = "/" + prefix
|
||||||
|
}
|
||||||
|
return http.StripPrefix(prefix, http.FileServer(http.FS(static.Static)))
|
||||||
}
|
}
|
||||||
|
|
||||||
func GetAssets() http.Handler {
|
func GetAssets(prefix string) http.Handler {
|
||||||
return http.StripPrefix("/static/", http.FileServer(http.FS(static.Static)))
|
if prefix != "" {
|
||||||
|
prefix = "/" + prefix + "static/"
|
||||||
|
} else {
|
||||||
|
prefix = "/static/"
|
||||||
|
}
|
||||||
|
return http.StripPrefix(prefix, http.FileServer(http.FS(static.Static)))
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetSessions renders the number of active sessions
|
// GetSessions renders the number of active sessions
|
||||||
|
@ -2,6 +2,7 @@ package api
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
|
|
||||||
"github.com/sosedoff/pgweb/pkg/command"
|
"github.com/sosedoff/pgweb/pkg/command"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -20,8 +21,8 @@ func SetupMiddlewares(group *gin.RouterGroup) {
|
|||||||
func SetupRoutes(router *gin.Engine) {
|
func SetupRoutes(router *gin.Engine) {
|
||||||
root := router.Group(command.Opts.Prefix)
|
root := router.Group(command.Opts.Prefix)
|
||||||
|
|
||||||
root.GET("/", gin.WrapH(GetHome()))
|
root.GET("/", gin.WrapH(GetHome(command.Opts.Prefix)))
|
||||||
root.GET("/static/*path", gin.WrapH(GetAssets()))
|
root.GET("/static/*path", gin.WrapH(GetAssets(command.Opts.Prefix)))
|
||||||
root.GET("/connect/:resource", ConnectWithBackend)
|
root.GET("/connect/:resource", ConnectWithBackend)
|
||||||
|
|
||||||
api := root.Group("/api")
|
api := root.Group("/api")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user