[CORS-POLICY] DZIAŁA!
This commit is contained in:
parent
bf48af50c6
commit
617fb64dbe
@ -6,16 +6,47 @@ package main
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/gin-gonic/contrib/static"
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
func Cors() gin.HandlerFunc {
|
||||
//https://razil.cc/post/2018/10/go-cors-request-on-gin/
|
||||
return func(c *gin.Context) {
|
||||
method := c.Request.Method
|
||||
|
||||
origin := c.Request.Header.Get("Origin")
|
||||
|
||||
if origin != "" {
|
||||
c.Header("Access-Control-Allow-Origin", origin)
|
||||
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization") //自定义 Header
|
||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
|
||||
c.Header("Access-Control-Allow-Credentials", "true")
|
||||
|
||||
}
|
||||
|
||||
if method == "OPTIONS" {
|
||||
c.Header("Access-Control-Allow-Origin", "*")
|
||||
c.Header("Access-Control-Allow-Headers", "Content-Type,AccessToken,X-CSRF-Token, Authorization") //自定义 Header
|
||||
c.Header("Access-Control-Allow-Methods", "POST, GET, OPTIONS")
|
||||
c.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
|
||||
c.Header("Access-Control-Allow-Credentials", "true")
|
||||
c.AbortWithStatus(http.StatusNoContent)
|
||||
}
|
||||
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// Set the router as the default one shipped with Gin
|
||||
router := gin.Default()
|
||||
router.Use(Cors())
|
||||
|
||||
// Serve frontend static files
|
||||
router.Use(static.Serve("/", static.LocalFile("./views", true)))
|
||||
// router.Use(static.Serve("/", static.LocalFile("./views", true)))
|
||||
|
||||
// config.AllowOrigins = []string{"http://localhost:8080/"}
|
||||
|
||||
// Setup route group for the API
|
||||
api := router.Group("/api")
|
||||
|
@ -147,6 +147,13 @@ func addNewCardView(c *gin.Context) {
|
||||
//ale dodawanei tutaj bo i tak mozna to zrobic w tej samem domenie co couchdb
|
||||
//PATRZ: documentation/couchdb/local.ini; documentation/couchdb/corsy_ustawienie.txt
|
||||
c.Header("Content-Type", "application/json")
|
||||
fmt.Println("------------------------------------------------------------------")
|
||||
fmt.Println("------------------------------------------------------------------")
|
||||
fmt.Println("------------------------------------------------------------------")
|
||||
fmt.Println("------------------------------------------------------------------")
|
||||
fmt.Println("------------------------------------------------------------------")
|
||||
fmt.Println("------------------------------------------------------------------")
|
||||
fmt.Println("------------------------------------------------------------------")
|
||||
|
||||
var newCard Card
|
||||
c.Bind(&newCard)
|
||||
|
@ -32,6 +32,8 @@
|
||||
|
||||
<script>
|
||||
import format from 'date-fns/format'
|
||||
import axios from 'axios'
|
||||
|
||||
export default {
|
||||
data(){
|
||||
return{
|
||||
@ -78,18 +80,14 @@ export default {
|
||||
cardObj.blank = blank
|
||||
cardObj.text = this.cardText
|
||||
|
||||
|
||||
axios.get(url_status, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
}
|
||||
}
|
||||
).then(function(response){
|
||||
vm.friendlist = response.data;
|
||||
})
|
||||
.catch(function(error){
|
||||
vm.friendlist = "An error occured: " + error;
|
||||
axios.get("http://127.0.0.1:3000/api/getUsersView" , { crossdomain: true }
|
||||
).then(function(response){
|
||||
console.log(response)
|
||||
})
|
||||
.catch(function(error){
|
||||
console.log("ERROR: ", error);
|
||||
});
|
||||
|
||||
this.$emit('cardAdded')
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user