mirror of
https://github.com/prymitive/karma
synced 2026-05-07 03:26:52 +00:00
Merge pull request #90 from prymitive/cors
fix(cors): change Access-Control-Allow-Origin validation to work in dev
This commit is contained in:
@@ -301,7 +301,7 @@ listen:
|
||||
prefix: string
|
||||
```
|
||||
|
||||
- `address` -
|
||||
- `address` - Hostname or IP to listen on.
|
||||
- `port` - HTTP port to listen on.
|
||||
- `prefix` - URL root for karma, you can use to if you wish to serve it from
|
||||
location other than `/`. This option is mostly useful when using karma behind
|
||||
|
||||
12
main.go
12
main.go
@@ -63,7 +63,17 @@ func setupRouter(router *gin.Engine) {
|
||||
// so we end up with /static/static/js
|
||||
router.Use(static.Serve(getViewURL("/static/static/js/"), staticSrcFileSystem))
|
||||
router.Use(cors.New(cors.Config{
|
||||
AllowAllOrigins: true,
|
||||
// This works different than AllowAllOrigins=true
|
||||
// 1. AllowAllOrigins will cause responses to include
|
||||
// 'Access-Control-Allow-Origin: *' header in all responses
|
||||
// 2. Setting AllowOriginFunc allows to validate origin URI and if it passes
|
||||
// the response will include 'Access-Control-Allow-Origin: $origin'
|
||||
// So the logic is the same, but implementation is different.
|
||||
// We need second behavior since setting `credentials: include` on JS
|
||||
// fetch() will fail with 'Access-Control-Allow-Origin: *' responses
|
||||
AllowOriginFunc: func(origin string) bool {
|
||||
return true
|
||||
},
|
||||
AllowCredentials: true,
|
||||
AllowMethods: []string{"GET", "POST", "DELETE"},
|
||||
AllowHeaders: []string{"Origin"},
|
||||
|
||||
Reference in New Issue
Block a user