backend fertig gestellt

frontend angefangen
This commit is contained in:
Husky
2022-01-04 19:01:33 +01:00
parent 71ac5d0a5b
commit d0bc77271e
47 changed files with 23070 additions and 0 deletions

83
main.go Normal file
View File

@@ -0,0 +1,83 @@
package main
import (
"path"
"path/filepath"
"git.cosysda.de/HuskyTeufel/Hochzeit/handlers"
"github.com/gin-gonic/gin"
)
var (
//audience string
//domain string
)
func main() {
//setAuth0Variables()
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))
}
}))
//authorized := r.Group("/")
//authorized.Use(authRequired())
r.GET("/besucher", handlers.GetBesucherListHandler)
r.POST("/besucher", handlers.AddBesucherHandler)
r.DELETE("/besucher/:id", handlers.DeleteBesucherHandler)
r.PUT("/besucher", handlers.ComeBesucherHandler)
err := r.Run(":3000")
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 setAuth0Variables() {
audience = "https://hochzeit-api" //os.Getenv("AUTH0_API_IDENTIFIER")
domain = "dev-uzlaiuax.eu.auth0.com/" //os.Getenv("AUTH0_DOMAIN")
}
func authRequired() gin.HandlerFunc {
return func(c *gin.Context) {
var auth0Domain = "https://" + domain + "/"
client := auth0.NewJWKClient(auth0.JWKClientOptions{URI: auth0Domain + ".well-known/jwks.json"}, nil)
configuration := auth0.NewConfiguration(client, []string{audience}, auth0Domain, jose.RS256)
validator := auth0.NewValidator(configuration, nil)
_, err := validator.ValidateRequest(c.Request)
if err != nil {
log.Println(err)
terminateWithError(http.StatusUnauthorized, "token is not valid", c)
return
}
c.Next()
}
}
*/
func terminateWithError(statusCode int, message string, c *gin.Context) {
c.JSON(statusCode, gin.H{"error": message})
c.Abort()
}