mirror of
https://github.com/cubixle/vault.git
synced 2026-04-30 18:38:43 +01:00
added cors
This commit is contained in:
@@ -1,11 +1,12 @@
|
|||||||
BINARY=vault
|
BINARY=vault
|
||||||
VERSION=test
|
VERSION=test
|
||||||
CONTAINER_PORT=-p 7007:7014
|
CONTAINER_PORT=-p 7007:7014
|
||||||
|
ENV=-e VAULT_APP_URL=vault.app
|
||||||
|
|
||||||
build:
|
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 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} .
|
docker build -t ${BINARY}:${VERSION} .
|
||||||
start:
|
start:
|
||||||
docker run -d ${CONTAINER_PORT} --name ${BINARY} ${BINARY}:${VERSION}
|
docker run -e ${ENV} -d ${CONTAINER_PORT} --name ${BINARY} ${BINARY}:${VERSION}
|
||||||
stop:
|
stop:
|
||||||
docker stop ${BINARY} && docker rm ${BINARY}
|
docker stop ${BINARY} && docker rm ${BINARY}
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"log"
|
"log"
|
||||||
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -28,12 +29,31 @@ type Vault struct {
|
|||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
router := gin.Default()
|
router := gin.Default()
|
||||||
|
router.Use(CORS(os.Getenv("VAULT_APP_URL")))
|
||||||
router.POST("/", createAction)
|
router.POST("/", createAction)
|
||||||
router.POST("/decrypt", decryptAction)
|
router.POST("/decrypt", decryptAction)
|
||||||
router.Run(":7014")
|
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) {
|
func show(c *gin.Context) {
|
||||||
log.Println("asdasdsa")
|
log.Println("asdasdsa")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user