Implemented CORS shit

This commit is contained in:
konrad 2017-11-09 12:19:37 +01:00 committed by kolaente
parent a56b76cdcf
commit 7641ea7ad3
Signed by: konrad
GPG Key ID: F40E70337AB24C9B
1 changed files with 15 additions and 0 deletions

View File

@ -26,6 +26,17 @@ func NewEcho() *echo.Echo {
// RegisterRoutes registers all routes for the application
func RegisterRoutes(e *echo.Echo) {
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
res := c.Response()
res.Header().Set("Access-Control-Allow-Origin", "*")
res.Header().Set("Access-Control-Allow-Methods", "GET, POST, PUT, DELETE")
res.Header().Set("Access-Control-Allow-Headers", "authorization,content-type")
res.Header().Set("Access-Control-Expose-Headers", "authorization,content-type")
return next(c)
}
})
// CORS
e.OPTIONS("/login", SetCORSHeader)
e.OPTIONS("/api/v1/books", SetCORSHeader)
@ -38,6 +49,10 @@ func RegisterRoutes(e *echo.Echo) {
// API Routes
a := e.Group("/api/v1")
a.POST("/login", Login)
a.OPTIONS("/login", SetCORSHeader)
// Lookup Books
a.GET("/books", apiv1.BookList)
a.GET("/books/:id", apiv1.BookShow)