Namespace is a query param
This commit is contained in:
20
view/json.go
20
view/json.go
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user