diff --git a/conf.go b/conf.go index fa48ce3..dd9453a 100644 --- a/conf.go +++ b/conf.go @@ -125,6 +125,7 @@ type Global struct { Excluded Globs `yaml:"excluded"` ViewURLBase string `yaml:"viewurlbase"` ViewPathBase string `yaml:"viewpathbase"` + RoutePrefix string `yaml:"routeprefix"` // if you want to proxy megauploader as a sub-location, that's for you } // UserHome specifies rules for generating home shares on the fly diff --git a/http.go b/http.go index ba2ffde..89a686f 100644 --- a/http.go +++ b/http.go @@ -47,15 +47,17 @@ func (mu *MegaUploader) confAcquire(inner func(w http.ResponseWriter, r *http.Re // SetupRoutes adds API routes func (mu *MegaUploader) SetupRoutes() { - http.HandleFunc("/", requireUserMiddleware(mu.home)) - http.HandleFunc("/upload/", requireUserMiddleware(mu.uploadUI)) + prefix := strings.TrimRight(mu.Conf.Global.RoutePrefix, "/") + + http.HandleFunc(prefix+"/", mu.confAcquire(requireUserMiddleware(mu.home))) + http.HandleFunc(prefix+"/upload/", mu.confAcquire(requireUserMiddleware(mu.uploadUI))) static := rice.MustFindBox("res/static") - http.HandleFunc("/static/", requireUserMiddleware( - http.StripPrefix("/static/", http.FileServer(static.HTTPBox())).ServeHTTP, + http.HandleFunc(prefix+"/static/", requireUserMiddleware( + http.StripPrefix(prefix+"/static/", http.FileServer(static.HTTPBox())).ServeHTTP, )) - http.HandleFunc("/api/share", requireUserMiddleware(mu.listShares)) - http.HandleFunc("/api/share/", requireUserMiddleware(mu.getShare)) - http.HandleFunc("/api/upload/", requireUserMiddleware(mu.upload)) + http.HandleFunc(prefix+"/api/share", mu.confAcquire(requireUserMiddleware(mu.listShares))) + http.HandleFunc(prefix+"/api/share/", mu.confAcquire(requireUserMiddleware(mu.getShare))) + http.HandleFunc(prefix+"/api/upload/", mu.confAcquire(requireUserMiddleware(mu.upload))) } func getUser(r *http.Request) (string, error) { diff --git a/httpui.go b/httpui.go index cb8c8cf..6a4ece3 100644 --- a/httpui.go +++ b/httpui.go @@ -48,6 +48,7 @@ func (mu *MegaUploader) home(w http.ResponseWriter, r *http.Request) { shares := mu.Conf.GetAuthShares(user) w.Header().Set("Content-Type", "text/html") tmpl.Execute(w, map[string]interface{}{ + "Prefix": mu.Conf.Global.RoutePrefix, "Shares": shares, }) } @@ -73,6 +74,7 @@ func (mu *MegaUploader) uploadUI(w http.ResponseWriter, r *http.Request) { } w.Header().Set("Content-Type", "text/html") tmpl.Execute(w, map[string]interface{}{ + "Prefix": mu.Conf.Global.RoutePrefix, "Share": share, "ViewURL": viewurl.String(), }) diff --git a/res/templates/index.html.tmpl b/res/templates/index.html.tmpl index f3475e6..7b5d8e5 100644 --- a/res/templates/index.html.tmpl +++ b/res/templates/index.html.tmpl @@ -6,7 +6,7 @@