Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
FEAT(Server) Negroni middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
fgruchala committed Apr 2, 2017
1 parent 5e2f337 commit 94e24f5
Show file tree
Hide file tree
Showing 13 changed files with 1,116 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Godeps/Godeps.json

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

17 changes: 12 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/rs/cors"
log "github.com/sirupsen/logrus"
"github.com/urfave/negroni"

"flag"

Expand Down Expand Up @@ -36,14 +37,20 @@ func main() {
router := mux.NewRouter().StrictSlash(true)
webservice.NewTweetWebservice(router, tweetService)

// CORS
// HTTP server
mux := http.NewServeMux()
mux.Handle("/", router)

// Middleware CORS
c := cors.New(cors.Options{
AllowedOrigins: []string{*corsOrigin},
AllowedMethods: []string{"GET"}})
handlerCors := c.Handler(mux)

// Middleware HTTP
n := negroni.Classic()
n.UseHandler(handlerCors)

mux := http.NewServeMux()
mux.Handle("/", router)
handler := c.Handler(mux)
log.WithFields(log.Fields{"port": *port}).Info("Starting server ...")
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", *port), handler))
log.Fatal(http.ListenAndServe(fmt.Sprintf(":%v", *port), n))
}
1 change: 1 addition & 0 deletions vendor/github.com/urfave/negroni/.gitignore

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

26 changes: 26 additions & 0 deletions vendor/github.com/urfave/negroni/.travis.yml

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

37 changes: 37 additions & 0 deletions vendor/github.com/urfave/negroni/CHANGELOG.md

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

21 changes: 21 additions & 0 deletions vendor/github.com/urfave/negroni/LICENSE

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

Loading

0 comments on commit 94e24f5

Please sign in to comment.