mirror of
https://github.com/cubixle/vault.git
synced 2026-04-30 20:38:44 +01:00
added cors
This commit is contained in:
@@ -1,11 +1,12 @@
|
||||
BINARY=vault
|
||||
VERSION=test
|
||||
CONTAINER_PORT=-p 7007:7014
|
||||
ENV=-e VAULT_APP_URL=vault.app
|
||||
|
||||
build:
|
||||
docker run --rm -v ${PWD}:/go/src/app -w /go/src/app -e GOOS=linux -e GOARCH=386 sipsynergy/go-builder /bin/sh -c "godep get && godep go build"
|
||||
docker build -t ${BINARY}:${VERSION} .
|
||||
start:
|
||||
docker run -d ${CONTAINER_PORT} --name ${BINARY} ${BINARY}:${VERSION}
|
||||
docker run -e ${ENV} -d ${CONTAINER_PORT} --name ${BINARY} ${BINARY}:${VERSION}
|
||||
stop:
|
||||
docker stop ${BINARY} && docker rm ${BINARY}
|
||||
|
||||
@@ -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