Skip to content

Commit

Permalink
Merge pull request spaceuptech#14 from Jayesh333/master
Browse files Browse the repository at this point in the history
enabled cors
  • Loading branch information
YourTechBud authored Feb 17, 2019
2 parents 24a831b + b23313b commit b775fdc
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ require (
github.com/nats-io/go-nats v1.7.0
github.com/nats-io/nkeys v0.0.2 // indirect
github.com/nats-io/nuid v1.0.0 // indirect
github.com/rs/cors v1.6.0
github.com/satori/go.uuid v1.2.0
github.com/spf13/viper v1.3.1
github.com/stretchr/testify v1.3.0 // indirect
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ github.com/pelletier/go-toml v1.2.0 h1:T5zMGML61Wp+FlcbWjRDT7yAxhJNAiPPLOFECq181
github.com/pelletier/go-toml v1.2.0/go.mod h1:5z9KED0ma1S8pY6P1sdut58dfprrGBbd/94hg7ilaic=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rs/cors v1.6.0 h1:G9tHG9lebljV9mfp9SNPDL36nCDxmo3zTlAf1YgvzmI=
github.com/rs/cors v1.6.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
github.com/spf13/afero v1.1.2 h1:m8/z1t7/fwjysjQRYbP0RD+bUIF/8tJwPdEZsI83ACI=
Expand Down
15 changes: 14 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net/http"

"github.com/gorilla/mux"
"github.com/rs/cors"

"github.com/spaceuptech/space-cloud/config"
"github.com/spaceuptech/space-cloud/modules/auth"
Expand Down Expand Up @@ -34,7 +35,19 @@ func initServer(isProd bool) *server {
}

func (s *server) start(port string) error {
return http.ListenAndServe(":"+port, s.router)
// Allow cors
corsObj := cors.New(cors.Options{
AllowCredentials: true,
AllowOriginFunc: func(s string) bool {
return true
},
AllowedMethods: []string{"GET", "PUT", "POST", "DELETE"},
AllowedHeaders: []string{"Authorization", "Content-Type"},
ExposedHeaders: []string{"Authorization", "Content-Type"},
})

handler := corsObj.Handler(s.router)
return http.ListenAndServe(":"+port, handler)
}

func (s *server) loadConfig(config *config.Project) error {
Expand Down

0 comments on commit b775fdc

Please sign in to comment.