0

express server config:

app.use(
    cors({
        origin: "*",
        methods: "GET,PUT,POST",
        allowedHeaders: "*",
        exposeHeaders: "*",
        optionsSuccessStatus: 200,
    })
);

//this fails as well
app.use(cors());

client side request:

let value= await axios({
   url: "https://my.api.here.cloud/verifyGroup",
   method: "post",
   data: data.value,
});
Access to XMLHttpRequest at 'https://my.api.here.cloud/verifyGroup' from origin 'https://my.frontend.here.cloud' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

I'm fairly confident it has something to do with AWS resources because in my local environment, these configs allow for cors but as soon as it's up on AWS, I'm getting blocked by cors.

I'm running an ECS Fargate service that's running a single task containing a frontend container and the backend container. Each of these containers has an ALB attached to them.

I came across this post here which gave me some hope, so I tried implementing it into my own solution but it still came up short.

my attempt at implementing the solution from the other post. This is what's being returned at an endpoint:

res.json({
  headers: {
     "Access-Content-Allow-Origin": "*",
  },
  statusCode: 200,
  body: {
     value: true,
  },
});
leed38
  • 314
  • 1
  • 4
  • 14
  • The AWS services you are using (ECS and a Load Balancer) would not modify the CORS response, or send a different CORS response. Are you sure the code you have in your question is the actual code running on ECS? I would start by debugging this in your web browser's developer console, to see what CORS response is currently coming back from your ECS service. – Mark B Apr 20 '22 at 14:29

0 Answers0