File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ import (
1414 "github.com/dgrijalva/jwt-go"
1515 "github.com/gorilla/mux"
1616 "github.com/joho/godotenv"
17+ "github.com/rs/cors"
1718)
1819
1920type Response struct {
@@ -66,6 +67,12 @@ func main() {
6667 SigningMethod : jwt .SigningMethodRS256 ,
6768 })
6869
70+ c := cors .New (cors.Options {
71+ AllowedOrigins : []string {"http://localhost:3000" },
72+ AllowCredentials : true ,
73+ AllowedHeaders : []string {"Authorization" },
74+ })
75+
6976 r := mux .NewRouter ()
7077
7178 // This route is always accessible
@@ -104,9 +111,10 @@ func main() {
104111 responseJSON (message , w , http .StatusOK )
105112 }))))
106113
114+ handler := c .Handler (r )
107115 http .Handle ("/" , r )
108116 fmt .Println ("Listening on http://localhost:3010" )
109- http .ListenAndServe ("0.0.0.0:3010" , nil )
117+ http .ListenAndServe ("0.0.0.0:3010" , handler )
110118}
111119
112120
You can’t perform that action at this time.
0 commit comments