Hello there, Welcome back to my page. Whether you're a returning visitor or visiting for the first time, Voila! I'm more than thrilled to have you here. Recently, I completed a full-stack project named "Talku-Talku". Although after sharing it with my...
vinyldavyl.hashnode.dev6 min read
It's an awesome and very helpfull article.
Hi, and thanks for this awesome article.
I have this MERN app I've deployed to Vercel (my GitHub username is DragonOsman. Please go to my GitHub page and go to the personal-library repo; the deployment link is on the right-hand panel). I setup CORS and a proxy (proxy key in client directory package.json that points to the server URL), and the paths and methods are all correct as far as I can see, but I still get a 405 error when I try to send a POST request to my login route.
Source code repository is on my personal-library repository (DragonOsman/personal-library). Any help is appreciated. [I have to describe like this because I can't post links yet.] Thanks.
Edit: I removed proxy and only kept CORS, which I'm doing like this:
const CLIENT_URL = "<client_url>";
app.use(cors({
origin: [`${CLIENT_URL}`, `${CLIENT_URL}/`],
methods: ["GET", "PUT", "POST", "DELETE"],
credentials: true
}));
but I still have a CORS error in my browser's console that says:
Access to fetch at '<backend_login_url>' from origin '<client_url>' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
I added res.setHeader("Access-Control-Allow-Origin", [CLIENT_URL,${CLIENT_URL}/]); on all my routes, right at the start of the function code block, and I also added app.options("*", cors()); (tried it both before and after my app.use(cors({...})) call). But that error won't go away. What should I do?
Wow, Thanks alot I'm guessing the vercel.json is quite important for the backend deploy
nasir
very help full