adds integrations with bookish-server, the books API and the google books API, adds functionality for library, searching for books, and displaying renters registered in the system

This commit is contained in:
David Lick
2020-05-28 22:08:27 -04:00
parent 888dec3402
commit a06b4d70ab
337 changed files with 17276 additions and 91 deletions
+1
View File
@@ -88,6 +88,7 @@ func (s *Server) UpdateMap() error {
func (s *Server) BuildRoutes() http.Handler {
r := chi.NewRouter()
r.Use(cors)
r.Use(middleware.RequestID)
r.Use(middleware.RealIP)
r.Use(middleware.Logger)
+17
View File
@@ -13,6 +13,23 @@ import (
"github.com/go-chi/chi"
)
// cors is a middlware that adds CORS headers to responses.
func cors(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Access-Control-Allow-Origin", "*")
w.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, PATCH, DELETE, OPTIONS")
w.Header().Set("Access-Control-Allow_Headers", "Origin, Content-Type, Accept, Authorization")
w.Header().Set("Access-Control-Allow-Credentials", "true")
w.Header().Set("Access-Control-Max-Age", "600")
if r.Method == "OPTIONS" {
return
}
next.ServeHTTP(w, r)
})
}
// renterCtx is a convenience handler to fetch the renter with the provided renterId URLParam.
func (s *Server) renterCtx(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {