System Information
- Strapi Version: 3.1.0-alpha.5
- Operating System: AWS EC2 → strAPI
- Database: mongodb
- Node Version: 12.19.0
- NPM Version: 6.14.9
- Yarn Version: 1.22.5
Hello everyone!
I want to use the for-got password function.
It works fine at localhost port 3000 → 1337 and I received it according to the set email platform.
Currently, the server is served by Amazon AWS.
In mydomain port 3000 → api.mydomain port 1337"
or localhost port 3000 → api.mydomain port 1337",
the for-got password is pending and a CORS error is returned.
Setting up ./config/middleware.js was done through strAPI documentation and searching.
Chrome developer tools console:
1.
Access to XMLHttpRequest at 'api.mydomain.com/auth/forgot-password' from origin
'localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is
present on the requested resource.
Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:84)
POST "api.mydomain.com/auth/forgot-password" net::ERR_FAILED
XHR failed loading: POST "/auth/forgot-password".
Code :
React.js [port: 3000]
await axios({
method: 'POST',
url: '/auth/forgot-password',
headers: {
'Content-Type': 'application/json',
},
data: {
email: `${email.value}@${emailAddress.value}`,
},
})
.then(response => {
console.log(response);
})
.catch(error => {
console.log(error);
});
config/middleware.js strAPI [Port: 1337]
module.exports = {
load: {
before: ["responseTime", "logger", "cors", "responses" ,"gzip"],
order: [],
after: ["parser", "router"],
},
settings: {
cors: {
enabled: true,
headers: ["*"],
origin: ["*"],
},
},
};
I need help.
Thank you.