Revert "TP-0000 | middleware (#41)" (#42)

This reverts commit 3713b793a3.
This commit is contained in:
Abhijeet Gupta
2023-04-27 00:03:32 +05:30
committed by GitHub Enterprise
parent 3713b793a3
commit 12ce39cb77

View File

@@ -56,23 +56,6 @@ func (s *Server) createMiddleware() gin.HandlerFunc {
return func(c *gin.Context) {
whitelistedDomains := getWhitelistedDomains()
//cors handling
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
c.Writer.Header().Set("Access-Control-Allow-Headers", viper.GetString("allowed.custom.headers"))
origin := c.Request.Header.Get("Origin")
if !whitelistedDomains[origin] {
c.AbortWithStatus(http.StatusUnauthorized)
return
}
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(http.StatusOK)
return
}
//auth handling
isAuthEnabled := viper.GetBool("auth.enabled")
if isAuthEnabled {
@@ -83,6 +66,21 @@ func (s *Server) createMiddleware() gin.HandlerFunc {
}
}
//cors handling
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
c.Writer.Header().Set("Access-Control-Allow-Headers", viper.GetString("allowed.custom.headers"))
origin := c.Request.Header.Get("Origin")
if !whitelistedDomains[origin] {
c.AbortWithStatus(http.StatusUnauthorized)
return
}
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(http.StatusOK)
return
}
startTime := time.Now()
c.Next()
endTime := float64(time.Since(startTime))