Finish migration

This commit is contained in:
Eden Kirin
2024-02-01 22:05:44 +01:00
parent 15ba332ae5
commit 89a3c63dd8
5 changed files with 27 additions and 273 deletions

View File

@ -1,70 +1 @@
package router
import (
"net/http"
"strings"
"github.com/gin-gonic/gin"
)
func isError(c *gin.Context, err error) bool {
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{
"details": err.Error(),
})
return true
}
return false
}
func raiseError(c *gin.Context, errCode int, message string) {
c.AbortWithStatusJSON(errCode, gin.H{
"details": message,
})
}
func raiseBadRequestError(c *gin.Context, message string) {
raiseError(c, http.StatusBadRequest, message)
}
func raiseNotFoundError(c *gin.Context, message string) {
raiseError(c, http.StatusNotFound, message)
}
func raiseInternalError(c *gin.Context, message string) {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"details": "Internal server error. We will we will fix it!",
})
}
func corsMiddleware() gin.HandlerFunc {
allowHeaders := [12]string{
"Content-Type",
"Content-Length",
"Accept-Encoding",
"X-CSRF-Token",
"Authorization",
"accept",
"origin",
"Cache-Control",
"X-Requested-With",
"x-timezone",
"Access-Control-Allow-Origin",
"Access-Control-Max-Age",
}
return func(c *gin.Context) {
allowOrigin := "*"
c.Writer.Header().Set("Access-Control-Allow-Origin", allowOrigin)
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers", strings.Join(allowHeaders[:], ", "))
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT, DELETE")
if c.Request.Method == "OPTIONS" {
c.AbortWithStatus(http.StatusNoContent)
return
}
c.Next()
}
}

View File

@ -53,13 +53,13 @@ func initRouter(app *fiber.App) {
app.Get("/", handlers.Home)
app.Get("/about", handlers.About)
// interactiveRouter := router.Group("/interactive")
// {
// interactiveRouter.GET("", handlers.Interactive)
// interactiveRouter.GET("/swap-content", handlers.InteractiveSwapContent)
// interactiveRouter.GET("/filter-cat-breeds", handlers.FilterCatBreeds)
// interactiveRouter.POST("/validate-form", handlers.ValidateForm)
// }
interactiveGroup := app.Group("/interactive")
{
interactiveGroup.Get("", handlers.Interactive)
interactiveGroup.Get("/swap-content", handlers.InteractiveSwapContent)
interactiveGroup.Get("/filter-cat-breeds", handlers.FilterCatBreeds)
interactiveGroup.Post("/validate-form", handlers.ValidateForm)
}
app.Static("/static", STATIC_PATH)
}