I have a 3 micro-services with Micronaut and a spring cloud gateway with spring boot
- Assessment
- Assessment-Bff
- Course
I have configurate the below gateway using yml
spring:
application:
name: spring-api-gateway
cloud:
gateway:
globalcors:
cors-configurations:
'[/**]':
allowedOrigins: "*"
allowedHeaders: "*"
allowedMethods:
- GET
- POST
- PUT
- DELETE
- OPTIONS
- HEAD
- PATCH
- TRACE
routes:
- id: course-service
uri:
${COURSE_SERVICE_URL:http://localhost:8081}
predicates:
- Path=/course/**, /swagger/**
- id: assessment-service-get
uri: ${ASSESSMENT_BFF_SERVICE_URL:http://localhost:8083}
predicates:
- Path=/assessment/**
- Method=GET
filters:
- RewritePath=/assessment/, /bff/assessment/
- id: assessment-service-post-put-delete
uri: ${ASSESSMENT_SERVICE_URL:http://localhost:8082}
predicates:
- Path=/assessment/**
- Method=POST,PUT,DELETE
Each micro-service has enabled the CORS configuration as below
micronaut.server.cors=true
Without the RewritePath I am not face CORS. However when using RewritePath keep facing the CORS from the front end
Access to XMLHttpRequest at 'http://localhost:8080/assessment' 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.