Static files now served; auth is broken
This commit is contained in:
parent
59b5574b16
commit
9637b38a3f
|
@ -4,6 +4,7 @@ import (
|
|||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
"github.com/danieljsummers/myPrayerJournal/src/api/data"
|
||||
)
|
||||
|
@ -38,3 +39,17 @@ func journal(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
sendJSON(w, r, reqs)
|
||||
}
|
||||
|
||||
func staticFiles(w http.ResponseWriter, r *http.Request) {
|
||||
// serve index for known routes handled client-side by the app
|
||||
for _, prefix := range ClientPrefixes {
|
||||
log.Print("Checking " + r.URL.Path)
|
||||
if strings.HasPrefix(r.URL.Path, prefix) {
|
||||
w.Header().Add("Content-Type", "text/html")
|
||||
http.ServeFile(w, r, "./public/index.html")
|
||||
return
|
||||
}
|
||||
}
|
||||
// 404 here is fine; quit hacking, y'all...
|
||||
http.ServeFile(w, r, "./public"+r.URL.Path)
|
||||
}
|
||||
|
|
|
@ -62,6 +62,5 @@ func NewRouter(cfg *AuthConfig) *vestigo.Router {
|
|||
router.Add(route.Method, route.Pattern, withAuth(route.Func, cfg))
|
||||
}
|
||||
}
|
||||
router.Get("/*", http.FileServer(http.Dir("/public")).ServeHTTP)
|
||||
return router
|
||||
}
|
||||
|
|
|
@ -21,9 +21,20 @@ type Routes []Route
|
|||
var routes = Routes{
|
||||
Route{
|
||||
"Journal",
|
||||
"GET",
|
||||
"/api/journal",
|
||||
http.MethodGet,
|
||||
"/api/journal/",
|
||||
journal,
|
||||
false,
|
||||
},
|
||||
// keep this route last
|
||||
Route{
|
||||
"StaticFiles",
|
||||
http.MethodGet,
|
||||
"/*",
|
||||
staticFiles,
|
||||
true,
|
||||
},
|
||||
}
|
||||
|
||||
// ClientPrefixes is a list of known route prefixes handled by the Vue app.
|
||||
var ClientPrefixes = []string{"/answered", "/journal", "/user"}
|
||||
|
|
Loading…
Reference in New Issue
Block a user