Skip to content

Commit 49d2f6a

Browse files
committed
Add cors
1 parent 9b2df46 commit 49d2f6a

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

go.mod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ go 1.15
44

55
require (
66
github.com/gorilla/websocket v1.4.2
7+
github.com/rs/cors v1.7.0
78
github.com/satori/go.uuid v1.2.0
89
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
22
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
3+
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
4+
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
35
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
46
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=

main.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package main
22

33
import (
44
"github.com/TouchDeck/websocket-proxy/pkg/proxy"
5+
"github.com/rs/cors"
56
"log"
67
"net/http"
78
)
@@ -17,7 +18,8 @@ func main() {
1718

1819
// Start the HTTP server.
1920
log.Println("Starting HTTP server on port 8783")
20-
err := http.ListenAndServe(":8783", mux)
21+
handler := cors.AllowAll().Handler(mux)
22+
err := http.ListenAndServe(":8783", handler)
2123
if err != nil {
2224
log.Fatalln("Error starting websocket server:", err)
2325
}

0 commit comments

Comments
 (0)