sreehari_jayaraj
03/08/2023, 6:31 PMSnackdex
03/08/2023, 6:33 PMsreehari_jayaraj
03/08/2023, 7:27 PMrouter := gin.Default()
// cors handling middlewares and supertokens middlewares
router.Use(gin.Recovery())
// CORS
router.Use(cors.New(cors.Config{
AllowOrigins: []string{"http://localhost:3000"},
AllowMethods: []string{"GET", "POST", "DELETE", "PUT", "OPTIONS"},
AllowHeaders: append([]string{"content-type"}, supertokens.GetAllCORSHeaders()...),
MaxAge: 1 * time.Minute,
AllowCredentials: true,
}))
router.Use(middlewares.Supertokens())
// use ginSwagger middleware to serve the API docs
router.GET("/", func(c *gin.Context) {
res := map[string]interface{}{
"data": "Server is up and running",
"ok": true,
}
c.JSON(http.StatusOK, res)
})
func Supertokens() gin.HandlerFunc {
return gin.HandlerFunc(func(c *gin.Context) {
supertokens.Middleware(http.HandlerFunc(
func(rw http.ResponseWriter, r *http.Request) {
c.Next()
})).ServeHTTP(c.Writer, c.Request)
// we call Abort so that the next handler in the chain is not called, unless we call Next explicitly
c.Abort()
})
}
Snackdex
03/08/2023, 7:29 PMsreehari_jayaraj
03/08/2023, 7:30 PMSnackdex
03/08/2023, 7:31 PMsreehari_jayaraj
03/08/2023, 7:34 PMSnackdex
03/08/2023, 7:42 PMsreehari_jayaraj
03/08/2023, 7:43 PMrp
03/09/2023, 5:21 AM