package main import ( "fmt" "path" "path/filepath" "git.cosysda.de/HuskyTeufel/Hochzeit/handlers" "github.com/gin-gonic/gin" ) func main() { fmt.Println("Hallo") r := gin.Default() r.Use(CORSMiddleware()) r.NoRoute((func(c *gin.Context) { dir, file := path.Split(c.Request.RequestURI) ext := filepath.Ext(file) if file == "" || ext == "" { c.File("./ui/dist/ui/index.html") } else { c.File("./ui/dist/ui/" + path.Join(dir, file)) } })) r.GET("/besucher", handlers.GetBesucherListHandler) r.POST("/besucher", handlers.AddBesucherHandler) r.DELETE("/besucher/:id", handlers.DeleteBesucherHandler) r.PUT("/besucher", handlers.ComeBesucherHandler) err := r.Run(":3001") if err != nil { panic(err) } } func CORSMiddleware() gin.HandlerFunc { return func(c *gin.Context) { c.Writer.Header().Set("Access-Control-Allow-Origin", "*") c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With") c.Writer.Header().Set("Access-Control-Allow-Methods", "DELETE, GET, OPTIONS, POST, PUT") if c.Request.Method == "OPTIONS" { c.AbortWithStatus(204) return } c.Next() } } /*func terminateWithError(statusCode int, message string, c *gin.Context) { c.JSON(statusCode, gin.H{"error": message}) c.Abort() } */