问题
I am trying to deploy a MERN Stack app to AWS but I am kinda stuck now.
Current Progress:
ALB is set up with a valid SSL Certificate issued by AWS.
ALB URL: https://xyz.alb.com/
Also, ALB has three listeners:
a. HTTP [80] b. HTTPS [443] c. HTTPS [5000] (For accessing ec2 backend server, is this right?)
EC2 instance public IP: 78.45.43.23 (Say)
(I can access my server on 78.45.43.23:5000/api/)
I have whitelisted, ALB, https://xyz.alb.com in my server CORS (Node) [Important].
Problem Statement:
When making an API call now to https://xyz.alb.com:5000/api/getUser, ideally, it should redirect to 78.45.43.23:5000/api/getUser and get me the response since I have the target instance setup [healthy ec2 instance].
But instead, I get,
Access to fetch at 'https://xyz.alb.com:5000/api/getUser' from origin 'https://xyz.alb.com' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
In short, I am not sure if I am being able to hit my server at PORT 5000 or not, by using the ALB URL!
I would be more than happy to provide any code/screenshot further needed to support my question.
Thanks in advance!
来源:https://stackoverflow.com/questions/63317832/aws-unable-to-make-api-calls-to-ec2-server-via-application-load-balancer-alb