CORS on AWS Elastic beanstalk
up vote
0
down vote
favorite
I'm new to AWS and used
Elastic beanstalk to deploy my rest API (api.example.com) in node- and S3 bucket with cloudfront for my static website (example.com) in React.
When calling the API endpoints from website, the browser is giving the CORS error. How can i prevent that?
I'm using following code in the node project for CORS
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Credentials', true)
res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
next();
});
Edit - based on arudzinska's comment
I also configured CORS in the bucket
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
</CORSRule>
</CORSConfiguration>
and the server is on nginx
Thanks in advance for any help
P.S - also, i have seen that few posts gives the reason as there would be some bug in the project code but all the endpoints are working correctly on POSTMAN.
amazon-web-services nginx cors amazon-elastic-beanstalk
add a comment |
up vote
0
down vote
favorite
I'm new to AWS and used
Elastic beanstalk to deploy my rest API (api.example.com) in node- and S3 bucket with cloudfront for my static website (example.com) in React.
When calling the API endpoints from website, the browser is giving the CORS error. How can i prevent that?
I'm using following code in the node project for CORS
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Credentials', true)
res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
next();
});
Edit - based on arudzinska's comment
I also configured CORS in the bucket
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
</CORSRule>
</CORSConfiguration>
and the server is on nginx
Thanks in advance for any help
P.S - also, i have seen that few posts gives the reason as there would be some bug in the project code but all the endpoints are working correctly on POSTMAN.
amazon-web-services nginx cors amazon-elastic-beanstalk
Did you configure CORS also on your bucket?
– arudzinska
9 hours ago
yes i did that in the bucket, please see the updated question
– Aman
8 hours ago
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I'm new to AWS and used
Elastic beanstalk to deploy my rest API (api.example.com) in node- and S3 bucket with cloudfront for my static website (example.com) in React.
When calling the API endpoints from website, the browser is giving the CORS error. How can i prevent that?
I'm using following code in the node project for CORS
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Credentials', true)
res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
next();
});
Edit - based on arudzinska's comment
I also configured CORS in the bucket
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
</CORSRule>
</CORSConfiguration>
and the server is on nginx
Thanks in advance for any help
P.S - also, i have seen that few posts gives the reason as there would be some bug in the project code but all the endpoints are working correctly on POSTMAN.
amazon-web-services nginx cors amazon-elastic-beanstalk
I'm new to AWS and used
Elastic beanstalk to deploy my rest API (api.example.com) in node- and S3 bucket with cloudfront for my static website (example.com) in React.
When calling the API endpoints from website, the browser is giving the CORS error. How can i prevent that?
I'm using following code in the node project for CORS
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*')
res.header('Access-Control-Allow-Credentials', true)
res.header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS')
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept')
next();
});
Edit - based on arudzinska's comment
I also configured CORS in the bucket
<?xml version="1.0" encoding="UTF-8"?>
<CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<CORSRule>
<AllowedOrigin>*</AllowedOrigin>
<AllowedMethod>GET</AllowedMethod>
<AllowedMethod>POST</AllowedMethod>
</CORSRule>
</CORSConfiguration>
and the server is on nginx
Thanks in advance for any help
P.S - also, i have seen that few posts gives the reason as there would be some bug in the project code but all the endpoints are working correctly on POSTMAN.
amazon-web-services nginx cors amazon-elastic-beanstalk
amazon-web-services nginx cors amazon-elastic-beanstalk
edited 8 hours ago
asked 9 hours ago
Aman
3917
3917
Did you configure CORS also on your bucket?
– arudzinska
9 hours ago
yes i did that in the bucket, please see the updated question
– Aman
8 hours ago
add a comment |
Did you configure CORS also on your bucket?
– arudzinska
9 hours ago
yes i did that in the bucket, please see the updated question
– Aman
8 hours ago
Did you configure CORS also on your bucket?
– arudzinska
9 hours ago
Did you configure CORS also on your bucket?
– arudzinska
9 hours ago
yes i did that in the bucket, please see the updated question
– Aman
8 hours ago
yes i did that in the bucket, please see the updated question
– Aman
8 hours ago
add a comment |
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
active
oldest
votes
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371763%2fcors-on-aws-elastic-beanstalk%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Did you configure CORS also on your bucket?
– arudzinska
9 hours ago
yes i did that in the bucket, please see the updated question
– Aman
8 hours ago