itsjamie / gin-cors Goto Github PK
View Code? Open in Web Editor NEWCross Origin Resource Sharing middleware for gin-gonic
License: MIT License
Cross Origin Resource Sharing middleware for gin-gonic
License: MIT License
Tags and versions aid in packaging for things like .deb files, and for anyone wanting to use Glide and other version based package managers to version their dependencies. It would also help ensure that if you make a breaking change, we don't pull it down until we are ready.
gin version v1.0rc2
config:
apiRouter.Use(middleware.Allow(middleware.Config{
Origins: "*",
Methods: "GET, PUT, POST, DELETE",
RequestHeaders: "Origin, Authorization, Content-Type, X-Wechat-Union-ID",
ExposedHeaders: "X-Total-Count",
}))
It will be convinient if git-cors has ability to fill a response header "Access-Control-Allow-Headers" with content of a request header "Access-Control-Request-Headers".
The middleware extended to implement pattern matching for allowed origins, to support comparing text strings that may contain wildcard syntax.
i didn't found any answer for this issue .
I am trying to call simple API, but it redirecting request 307
. and the request fail on client side .
as you see in the first screen shot there is 3 requests . first one is option with Status Code:200 OK
.
the next 2 requests with Status Code:307 Temporary Redirect
port 3030 is server
port 8100 is client
CORS middleware is gin-cors
and this is the code
// Creates a gin router with default middleware:
router := gin.Default()
// Apply the middleware to the router (works with groups too)
router.Use(cors.Middleware(cors.Config{
Origins: "*",
Methods: "GET, PUT, POST, DELETE",
RequestHeaders: "Origin, Authorization, Content-Type",
ExposedHeaders: "",
MaxAge: 300 * time.Second,
Credentials: false,
ValidateHeaders: false,
}))
router.POST("/api/v1/login", usersController.Login)
client side error
XMLHttpRequest cannot load http://localhost:3030/api/v1/login/. Redirect from
'http://localhost:3030/api/v1/login/' to 'http://localhost:3030/api/v1/login' has been blocked by CORS
policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin
'http://localhost:8100' is therefore not allowed access.
it works fine on postman
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.