Skip to content

Commit

Permalink
Merge pull request #46 from erizocosmico/feature/cors
Browse files Browse the repository at this point in the history
enable CORS on REST server
  • Loading branch information
smola authored Jun 29, 2017
2 parents a2d5c22 + 6eef12d commit f5035ff
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 7 deletions.
25 changes: 19 additions & 6 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ import:
- package: github.com/oklog/ulid
- package: github.com/Sirupsen/logrus
- package: gopkg.in/src-d/enry.v1
- package: github.com/rs/cors
version: ^1.1.0
testImport:
- package: github.com/stretchr/testify
subpackages:
Expand Down
8 changes: 7 additions & 1 deletion rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/bblfsh/sdk/protocol"
"github.com/bblfsh/server/runtime"
"github.com/gin-gonic/gin"
"github.com/rs/cors"
)

type RESTServer struct {
Expand All @@ -27,11 +28,16 @@ func (s *RESTServer) Serve(addr string) error {

protocol.DefaultParser = s.Server
r.POST("/parse", s.handleParse)
cors := cors.New(cors.Options{
AllowedOrigins: []string{"*"},
AllowedMethods: []string{"GET", "POST"},
AllowedHeaders: []string{"Content-Type", "Authorization"},
})

logrus.Info("starting REST server")
server := &http.Server{
Addr: addr,
Handler: r,
Handler: cors.Handler(r),
ReadTimeout: 1 * time.Minute,
WriteTimeout: 5 * time.Minute,
}
Expand Down

0 comments on commit f5035ff

Please sign in to comment.