Static files now served; auth is broken

This commit is contained in:
Daniel J. Summers 2018-03-24 13:37:18 -05:00
parent 59b5574b16
commit 9637b38a3f
3 changed files with 28 additions and 3 deletions

View File

@ -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)
}

View File

@ -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
}

View File

@ -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"}