Add BaseURL configuration (fixes #103)

This commit is contained in:
Deluan
2020-04-03 17:50:42 -04:00
parent b8eb22d162
commit 75cd21da1f
17 changed files with 61 additions and 25 deletions
+10 -9
View File
@@ -15,22 +15,23 @@ import (
)
type Router struct {
ds model.DataStore
mux http.Handler
path string
ds model.DataStore
mux http.Handler
}
func New(ds model.DataStore, path string) *Router {
r := &Router{ds: ds, path: path}
r.mux = r.routes()
return r
func New(ds model.DataStore) *Router {
return &Router{ds: ds}
}
func (app *Router) Setup(path string) {
app.mux = app.routes(path)
}
func (app *Router) ServeHTTP(w http.ResponseWriter, r *http.Request) {
app.mux.ServeHTTP(w, r)
}
func (app *Router) routes() http.Handler {
func (app *Router) routes(path string) http.Handler {
r := chi.NewRouter()
r.Post("/login", Login(app.ds))
@@ -52,7 +53,7 @@ func (app *Router) routes() http.Handler {
// Serve UI app assets
r.Handle("/", ServeIndex(app.ds))
r.Handle("/*", http.StripPrefix(app.path, http.FileServer(assets.AssetFile())))
r.Handle("/*", http.StripPrefix(path, http.FileServer(assets.AssetFile())))
return r
}