I have enabled CORS in my nodejs server that is using express as a middleware but i am still getting
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource
I have tried enabling cors and solutions suggested here Using CORS Still Give Cross Origin Error
But it still doesn't work for me.
app.use(cors())
app.options('*',cors())
app.use((req, res, next) => {
res.header('Access-Control-Allow-Origin', '*');
// authorized headers for preflight requests
// https://developer.mozilla.org/en-US/docs/Glossary/preflight_request
res.header('Access-Control-Allow-Headers', 'Origin, X-Requested-With, Content-Type, Accept');
next();
app.options('*', (req, res) => {
// allowed XHR methods
res.header('Access-Control-Allow-Methods', 'GET, PATCH, PUT, POST, DELETE, OPTIONS');
res.send();
});
});
This how i am creating request in front-end nextjs
app.
const requestBody={
bnb: address
}
let config = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
}
}
axios.post(methods.verify_bnb, qs.stringify(requestBody), config)
//
I should be able to make request and server to process it as i have enabled cors but it is still throwing mentioned errors.