Add ability to launch pgweb with url prefix
This commit is contained in:
parent
f308d1cfde
commit
0a144a633d
2
main.go
2
main.go
@ -104,7 +104,7 @@ func handleSignals() {
|
||||
}
|
||||
|
||||
func openPage() {
|
||||
url := fmt.Sprintf("http://%v:%v", options.HttpHost, options.HttpPort)
|
||||
url := fmt.Sprintf("http://%v:%v/%s", options.HttpHost, options.HttpPort, options.Prefix)
|
||||
fmt.Println("To view database open", url, "in browser")
|
||||
|
||||
if options.SkipOpen {
|
||||
|
@ -2,6 +2,7 @@ package api
|
||||
|
||||
import (
|
||||
"log"
|
||||
"strings"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
|
||||
@ -12,7 +13,9 @@ import (
|
||||
// Middleware function to check database connection status before running queries
|
||||
func dbCheckMiddleware() gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if allowedPaths[c.Request.URL.Path] == true {
|
||||
path := strings.Replace(c.Request.URL.Path, command.Opts.Prefix, "", -1)
|
||||
|
||||
if allowedPaths[path] == true {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
@ -14,10 +14,12 @@ func SetupMiddlewares(group *gin.RouterGroup) {
|
||||
}
|
||||
|
||||
func SetupRoutes(router *gin.Engine) {
|
||||
router.GET("/", GetHome)
|
||||
router.GET("/static/*path", GetAsset)
|
||||
group := router.Group(command.Opts.Prefix)
|
||||
|
||||
api := router.Group("/api")
|
||||
group.GET("/", GetHome)
|
||||
group.GET("/static/*path", GetAsset)
|
||||
|
||||
api := group.Group("/api")
|
||||
{
|
||||
SetupMiddlewares(api)
|
||||
|
||||
|
@ -2,6 +2,7 @@ package command
|
||||
|
||||
import (
|
||||
"os"
|
||||
"strings"
|
||||
|
||||
"github.com/jessevdk/go-flags"
|
||||
)
|
||||
@ -22,6 +23,7 @@ type Options struct {
|
||||
AuthPass string `long:"auth-pass" description:"HTTP basic auth password"`
|
||||
SkipOpen bool `short:"s" long:"skip-open" description:"Skip browser open on start"`
|
||||
Sessions bool `long:"sessions" description:"Enable multiple database sessions" default:"false"`
|
||||
Prefix string `long:"prefix" description:"Add a url prefix"`
|
||||
}
|
||||
|
||||
var Opts Options
|
||||
@ -40,5 +42,9 @@ func ParseOptions() error {
|
||||
Opts.Sessions = true
|
||||
}
|
||||
|
||||
if Opts.Prefix != "" && !strings.Contains(Opts.Prefix, "/") {
|
||||
Opts.Prefix = Opts.Prefix + "/"
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -5,15 +5,15 @@
|
||||
<meta charset="utf-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta http-equiv="Content-Language" content="en">
|
||||
<link rel="stylesheet" href="/static/css/bootstrap.css"></link>
|
||||
<link rel="stylesheet" href="/static/css/font-awesome.css"></link>
|
||||
<link rel="stylesheet" href="/static/css/app.css"></link>
|
||||
<link rel="icon" type="image/x-icon" href="/static/img/icon.ico" />
|
||||
<script type="text/javascript" src="/static/js/jquery.js"></script>
|
||||
<script type="text/javascript" src="/static/js/ace.js"></script>
|
||||
<script type="text/javascript" src="/static/js/ace-pgsql.js"></script>
|
||||
<script type="text/javascript" src="/static/js/bootstrap-contextmenu.js"></script>
|
||||
<script type="text/javascript" src="/static/js/app.js"></script>
|
||||
<link rel="stylesheet" href="static/css/bootstrap.css"></link>
|
||||
<link rel="stylesheet" href="static/css/font-awesome.css"></link>
|
||||
<link rel="stylesheet" href="static/css/app.css"></link>
|
||||
<link rel="icon" type="image/x-icon" href="static/img/icon.ico" />
|
||||
<script type="text/javascript" src="static/js/jquery.js"></script>
|
||||
<script type="text/javascript" src="static/js/ace.js"></script>
|
||||
<script type="text/javascript" src="static/js/ace-pgsql.js"></script>
|
||||
<script type="text/javascript" src="static/js/bootstrap-contextmenu.js"></script>
|
||||
<script type="text/javascript" src="static/js/app.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div id="main">
|
||||
|
@ -63,7 +63,7 @@ function apiCall(method, path, params, cb) {
|
||||
|
||||
$.ajax({
|
||||
timeout: timeout,
|
||||
url: "/api" + path,
|
||||
url: "api" + path,
|
||||
method: method,
|
||||
cache: false,
|
||||
data: params,
|
||||
|
Loading…
x
Reference in New Issue
Block a user