My API is not accepting requests from the domain set on the cors origin config
Relevant api code
async function bootstrap() {
const app = await NestFactory.create(AppModule);
app.enableCors({
origin: 'https://finad.devluis.tech',
allowedHeaders: [
'Content-Type'
],
credentials: true,
});
await app.listen(process.env.PORT || 8888);
}
Relevant web app code
const submitForm = async (e: FormEvent) => {
e.preventDefault();
await fetch(`https://api.finad.devluis.tech/user`, {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: `${name} ${lastName}`,
email: email,
password: password
})
});
}
If i remove the allowedHeaders part from my cors config, and the headers from the web app request it does not return me an error, but the body of the request is lost
I'm getting both this errors, one for each request (options and post)
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.finad.devluis.tech/user. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). Status code: 404.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.finad.devluis.tech/user. (Reason: CORS request did not succeed). Status code: (null).
Maybe relevant data:
- both the apps are hosted on Vercel
- my API is in the subdomain api.finad.devluis.tech
- my Webapp is in the subdomain finad.devluis.tech