support proxy prefix
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
"regexp"
|
||||
"time"
|
||||
|
||||
_ "github.com/jinzhu/gorm/dialects/sqlite"
|
||||
@@ -21,6 +22,7 @@ func main() {
|
||||
musicPath := set.String("music-path", "", "path to music")
|
||||
dbPath := set.String("db-path", "gonic.db", "path to database (optional)")
|
||||
scanInterval := set.Int("scan-interval", 0, "interval (in minutes) to automatically scan music (optional)")
|
||||
proxyPrefix := set.String("proxy-prefix", "", "url path prefix to use if behind proxy. eg '/gonic' (optional)")
|
||||
_ = set.String("config-path", "", "path to config (optional)")
|
||||
showVersion := set.Bool("version", false, "show gonic version")
|
||||
if err := ff.Parse(set, os.Args[1:],
|
||||
@@ -42,11 +44,14 @@ func main() {
|
||||
log.Fatalf("error opening database: %v\n", err)
|
||||
}
|
||||
defer db.Close()
|
||||
proxyPrefixExpr := regexp.MustCompile(`^\/*(.*?)\/*$`)
|
||||
*proxyPrefix = proxyPrefixExpr.ReplaceAllString(*proxyPrefix, `/$1`)
|
||||
serverOptions := server.Options{
|
||||
DB: db,
|
||||
MusicPath: *musicPath,
|
||||
ListenAddr: *listenAddr,
|
||||
ScanInterval: time.Duration(*scanInterval) * time.Minute,
|
||||
ProxyPrefix: *proxyPrefix,
|
||||
}
|
||||
log.Printf("using opts %+v\n", serverOptions)
|
||||
s := server.New(serverOptions)
|
||||
|
||||
Reference in New Issue
Block a user