Skip to content

Commit

Permalink
fix cors (#183)
Browse files Browse the repository at this point in the history
* copy all headers from fake ResponseWriter to ResponseWriter

* add tests

* use our cors middleware instead cors by rs

* remove unused vendor and debugs

* fix when request is with not allowed method
  • Loading branch information
felipeweb authored and cassiobotaro committed Jul 19, 2017
1 parent 55606d9 commit fc70b77
Showing 1 changed file with 0 additions and 13 deletions.
13 changes: 0 additions & 13 deletions root.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"github.com/nuveo/prest/config/router"
"github.com/nuveo/prest/controllers"
"github.com/nuveo/prest/middlewares"
"github.com/rs/cors"
"github.com/spf13/cobra"
"github.com/urfave/negroni"
// postgres driver for migrate
Expand Down Expand Up @@ -52,32 +51,20 @@ func Execute() {
func app() {
n := cfgMiddleware.GetApp()
r := router.Get()

r.HandleFunc("/databases", controllers.GetDatabases).Methods("GET")
r.HandleFunc("/schemas", controllers.GetSchemas).Methods("GET")
r.HandleFunc("/tables", controllers.GetTables).Methods("GET")
r.HandleFunc("/_QUERIES/{queriesLocation}/{script}", controllers.ExecuteFromScripts)
r.HandleFunc("/{database}/{schema}", controllers.GetTablesByDatabaseAndSchema).Methods("GET")

crudRoutes := mux.NewRouter().PathPrefix("/").Subrouter().StrictSlash(true)

crudRoutes.HandleFunc("/{database}/{schema}/{table}", controllers.SelectFromTables).Methods("GET")
crudRoutes.HandleFunc("/{database}/{schema}/{table}", controllers.InsertInTables).Methods("POST")
crudRoutes.HandleFunc("/{database}/{schema}/{table}", controllers.DeleteFromTable).Methods("DELETE")
crudRoutes.HandleFunc("/{database}/{schema}/{table}", controllers.UpdateTable).Methods("PUT", "PATCH")

r.PathPrefix("/").Handler(negroni.New(
middlewares.AccessControl(),
negroni.Wrap(crudRoutes),
))

if config.PrestConf.CORSAllowOrigin != nil {
c := cors.New(cors.Options{
AllowedOrigins: config.PrestConf.CORSAllowOrigin,
})
n.Use(c)
}

n.UseHandler(r)
n.Run(fmt.Sprintf(":%v", config.PrestConf.HTTPPort))
}

0 comments on commit fc70b77

Please sign in to comment.