Namespace is a query param

This commit is contained in:
Bel LaPointe
2020-07-24 12:42:42 -06:00
parent 0e980b1128
commit 11e7d13cca
5 changed files with 76 additions and 31 deletions

View File

@@ -26,20 +26,18 @@ func jsonHandler(g storage.Graph) http.Handler {
foo func(g storage.Graph, w http.ResponseWriter, r *http.Request) error
}{
{
path: "/who/",
path: "/who",
foo: who,
},
{
path: config.New().FilePrefix,
path: config.New().FilePrefix + "/",
foo: files,
},
}
for _, route := range routes {
nopath := strings.TrimRight(route.path, "/")
path := nopath + "/"
foo := route.foo
mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) {
mux.HandleFunc(route.path, func(w http.ResponseWriter, r *http.Request) {
if err := foo(g, w, r); err != nil {
status := http.StatusInternalServerError
if strings.Contains(err.Error(), "collision") {
@@ -49,17 +47,13 @@ func jsonHandler(g storage.Graph) http.Handler {
http.Error(w, string(b), status)
}
})
mux.HandleFunc(nopath, http.NotFound)
}
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
/*
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Content-Type", "application/json")
w.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PUT, DELETE, OPTIONS, TRACE")
w.Header().Set("Access-Control-Allow-Headers", "Accept, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
*/
if err := Auth(g, w, r); err != nil {
log.Println(err)
return
}
if gziphttp.Can(r) {
gz := gziphttp.New(w)
defer gz.Close()