Search code examples
spring-bootspring-cloudspring-cloud-gatewaystacksaga

CORS error when accessing the services thorough the StackSaga Admin server


I tried to access my order-service through the StackSaga admin server. The request goes through the Spring Cloud API gateway as well. but unfortunately, all the time I am getting a CORS error at the browser console.

enter image description here

enter image description here


Solution

  • When you try to access the stacksaga event-store API through the Spring Cloud API gateway you have to allow the Origins for the admin server. for instance, if the admin server running on the port localhost:4444 you have to allow the Origins for all the endpoints that go through the API gateway that contains stacksaga/ (because all the event-store API endpoints are started with stacksaga) like below in the yaml file (or .properties file).

    spring:
      cloud:
        gateway:
          globalcors:
            corsConfigurations:
              '[/*/stacksaga/**]':
                allowedOrigins:
                  - "http://localhost:44441"
                allowedMethods: "*"
                allowedHeaders: "*"
          default-filters:
            - DedupeResponseHeader=Access-Control-Allow-Credentials Access-Control-Allow-Origin
    

    This is actually not related to StackSaga framework. read this document for more information.