I have made simple expressJS server with nodemailer and have hosted it on aws elastic beanstalk, after which I was provided a 'http' link for the same, but I entered that link in my website which was hosted on netlify, it threw an error stating that an 'https' website cannot access 'http' website, so I converted my aws link to 'https' link, but after that I got an cors error from my netlify website.
I've tried multiple things, including importing the cors library from express like this:
`
const corsOptions = {
origin: [
/\.netlify\.app$/,
],
methods: ['GET', 'POST']
}
app.use(cors(corsOptions));
`
or setting headers like:
`
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
but these methods did not work either, I always get the same error:
access has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.` Please Help me resolve this error, I want to enable cors.
Comments
Post a Comment