0

I have a Springboot Microservice application. I have 4 microservices in my application.

API-gateway,
user-management,
idm-service,
engine-service.

I am using react as frontend here.

API-gateway contains CORS related configuration and I am using web-socket for my engine-service so it has web socket configuration. I am facing issue while communicating with socket of engine-service. When I am trying to initiate socket connection from react. First it will go to API-gateway so I have to add required CORS configuration in API-gateway.

API-gateway configuration:

cors-configurations:
  '[/**]':
    allowCredentials: true
    allowedOrigins:
      - "http://localhost:3000"
    allowedHeaders: "*"
    allowedMethods:
      - GET
      - POST
      - DELETE
      - PUT
      - OPTIONS
      - PATCH

I have to add allowCredentials: true to allow web socket connection and it is working fine.

engine-service socket configuration:

@Override
  public void registerStompEndpoints(StompEndpointRegistry registry) {
    registry.addEndpoint(registryEndpoint).setAllowedOrigins("http://localhost:3000").withSockJS();
  }

Now again I have to add setAllowedOrigins in websocket configuration. so when request comes to engine-service, I am getting error like this

The 'Access-Control-Allow-Origin' header contains multiple values 'http://localhost:3000, http://localhost:3000', but only one is allowed.

Now I am unable to find solution for this. All the request must go via API-gateway so I have to add CORS configuration there else I will get CORS error in API-gateway. If I am adding setAllowedOrigins in API-gateway I am getting error in engine-service.

Can you please guide me on this error? For websocket connection, Should I directly communicate with engine-service and not going via API-gateway?

2
  • Does this solve you query stackoverflow.com/questions/54497267/…? Commented Sep 23, 2024 at 10:49
  • Yes, it is working fine. Thank you so much for the answer. Commented Sep 25, 2024 at 13:15

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.