Skip to content

Commit bb1561b

Browse files
committed
CORS support
1 parent 6a3364b commit bb1561b

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

rxtx.go

+12-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import (
66
"os"
77
"time"
88

9+
"net/http"
10+
911
"github.com/bhoriuchi/go-bunyan/bunyan"
1012
"github.com/cjimti/gin-bunyan"
1113
"github.com/cjimti/rxtx/rtq"
@@ -68,9 +70,18 @@ func main() {
6870
// use bunyan logger
6971
r.Use(ginbunyan.Ginbunyan(&blog))
7072

71-
r.POST("/rx/:producer/:key/*label", rtq.RxRouteHandler)
73+
rxRoute := "/rx/:producer/:key/*label"
74+
r.POST(rxRoute, rtq.RxRouteHandler)
75+
r.OPTIONS(rxRoute, preflight)
7276

7377
blog.Info("Listening on port %s", *port)
7478
// block on server run
7579
r.Run(":" + *port)
7680
}
81+
82+
// CORS
83+
func preflight(c *gin.Context) {
84+
c.Header("Access-Control-Allow-Origin", "*")
85+
c.Header("Access-Control-Allow-Headers", "access-control-allow-origin, access-control-allow-headers")
86+
c.JSON(http.StatusOK, struct{}{})
87+
}

0 commit comments

Comments
 (0)