mirror of
https://github.com/cubixle/vault.git
synced 2026-04-24 23:04:44 +01:00
added cors
This commit is contained in:
22
main.go
22
main.go
@@ -9,6 +9,7 @@ import (
|
||||
"fmt"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
@@ -28,12 +29,31 @@ type Vault struct {
|
||||
|
||||
func main() {
|
||||
router := gin.Default()
|
||||
|
||||
router.Use(CORS(os.Getenv("VAULT_APP_URL")))
|
||||
router.POST("/", createAction)
|
||||
router.POST("/decrypt", decryptAction)
|
||||
router.Run(":7014")
|
||||
}
|
||||
|
||||
// CORS handles setting up the CORS security headers.
|
||||
func CORS(allowOrigin string) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
c.Writer.Header().Set("Access-Control-Allow-Origin", allowOrigin)
|
||||
c.Writer.Header().Set("Access-Control-Max-Age", "86400")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, GET, OPTIONS, PATCH, DELETE, UPDATE")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Headers", "Origin, Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization")
|
||||
c.Writer.Header().Set("Access-Control-Expose-Headers", "Content-Length")
|
||||
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
||||
|
||||
if c.Request.Method == "OPTIONS" {
|
||||
fmt.Println("OPTIONS")
|
||||
c.AbortWithStatus(200)
|
||||
} else {
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func show(c *gin.Context) {
|
||||
log.Println("asdasdsa")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user