spring-cloud / spring-cloud/spring-cloud-gateway

Cors Pre Flight Request

Open
#1,665 28 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback-provided
Dominant language
Java
Stars
4.9k
Forks
3.5k
Avg merge
20h 57m
Merged PRs (30d)
8

Description

Describe the bug
i'm using spring cloud Hoxton.SR3 and spring boot 2.2.6.RELEASE.
i have a problem when using angular 2+ call to api-gateway : "Access to XMLHttpRequest at 'http://localhost:8080/auth/oauth/token' from origin 'http://localhost:4200' 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."
config api-gateway :
spring:
cloud:
gateway:
default-filters:
- DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
routes:
- id: auth-service
uri: lb://auth-service
predicates:
- Path=/auth/**
- id: product-service
uri: lb://product-service
predicates:
- Path=/product/**
- id: order-service
uri: lb://order-service
predicates:
- Path=/order/**
- id: payment-service
uri: lb://payment-service
predicates:
- Path=/payment/**
globalcors:
corsConfigurations:
'[/**]':
allowedOrigins: ""
allowedHeader: "
"
allowCredentials: true
allowedMethods: "*"
add-to-simple-url-handler-mapping: true
i have tried add @CrossOrigin in gateway main class or add method Options in predicates in route[i] but it not work.
Please help me .
I think the problem lies in the version of the cloud

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reviewing the API gateway's supplied globalcors configuration and the Angular request to /auth/oauth/token, focusing on the preflight response. Reproduce the request and verify that the gateway returns the required Access-Control-Allow-Origin header and handles the configured OPTIONS request.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, java, spring, spring-boot
Domain
api, backend, web-dev
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.