Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' #36

Open
computerprince opened this issue Apr 14, 2022 · 0 comments

Comments

@computerprince
Copy link

Hi I followed the recommendation about cors from the document, but I'm still get the following error:

Access to XMLHttpRequest at 'http:///api/v1/payment' from origin 'http://' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.

This is my configuration:

endpoints:

[
{
"@comment": "this won't fail because CORS preflight headers are removed from the request to the backend",
"endpoint": "/api/v1/payment",
"input_headers": [
"*"
],
"output_encoding": "no-op",
"backend": [
{
"url_pattern": "/api/v1/payment",
"host": [
"http://*****"
],
"encoding": "no-op",
"extra_config": {
"modifier/martian": {
"fifo.Group": {
"scope": [
"request",
"response"
],
"aggregateErrors": true,
"modifiers": [
{
"header.Blacklist": {
"scope": [
"request"
],
"names": [
"Access-Control-Request-Method",
"Sec-Fetch-Dest",
"Sec-Fetch-Mode",
"Sec-Fetch-Site",
"Origin"
]
}
}
]
}
}
}
}
]
}
]

Krakend.json :

{
"version": 3,
"port": {{ marshal .service.port }},
"cache_ttl": {{ marshal .service.cache_ttl }},
"timeout": {{ marshal .service.timeout }},
"extra_config": {{ marshal .service.extra_config }},
"host": {{ marshal .service.default_hosts }},
"endpoints": [
{{ range $idx, $endpoint := .endpoint.example_group }}
{{if $idx}},{{end}}
{
"endpoint": "{{ $endpoint.endpoint }}",
"method": "{{ $endpoint.method }}",
"headers_to_pass":["*"],
"extra_config:":{{ marshal $endpoint.extra_config }},
"output_encoding": "no-op",
"backend": {{ marshal $endpoint.backend }}
}
{{ end }}

    ]
}

service.json
{
"port": 8080,
"cache_ttl": "3600s",
"timeout": "36s",
"default_hosts": [
"http://:30003",
"http://
:30004",
"http://:30007"
],
"extra_config": {
"security/cors": {
"allow_origins": [
"http*"
],
"allow_methods": [
"GET",
"HEAD",
"POST",
"PUT",
"DELETE"
],
"expose_headers": [
"Content-Length",
"Content-Type"
],
"allow_headers": [
"Origin",
"Authorization",
"Content-Type",
"Cache-Control",
"Pragma",
"Accept-Language"
],
"max_age": "12h",
"allow_credentials": false,
"debug": false
},
"telemetry/logging": {
"level": "DEBUG",
"prefix": "[KRAKEND]",
"syslog": false,
"stdout": true
},
"telemetry/opencensus": {
"exporters": {
"jaeger": {
"endpoint": "
/api/traces",
"service_name": "krakend",
"buffer_max_count": 1000
}
}
},
"telemetry/metrics": {
"collection_time": "60s",
"proxy_disabled": false,
"router_disabled": false,
"backend_disabled": false,
"endpoint_disabled": false,
"listen_address": ":8090"
}
}
}

Could you please tell me where I made a mistake?

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant