#CORS PATCH method refused despite configuration allowing it

1 messages · Page 1 of 1 (latest)

sterile cargo
#

Hello everyone,
New to developing, NodeJS and Express here (also not english native). I am stuck on a project where i got a frontend app (living on localhost:3000) and a backend app (living on localhost:5000) and i am trying to send a patch request to my server using Axios. i configured my backend app the following way:

app.use(cors(
  {
    methods: "HEAD,GET,PUT,PATCH,POST,UPDATE,DELETE",
    origin: "*",
    preflightContinue: true,

  },
));

Here my axios call.

  const handleSubmit = (e) => {
    e.preventDefault();
    axios
      .patch(
        `${process.env.REACT_APP_API}/user/update/${id}`, user)
      .then((res) => {});

    closeModal(true);
  };

Still, when the call runs, i've got CORS error: PATH method not allowed.
I tested my backend code using POSTMAN client and it worked.
What can i do to fix this error in my code?
Thank you for your answers. 🙂

hollow marsh
#

You need to make a preflight one.

#

Extract that call to cors out to a const, call it, say, corsMw

#

Then app.use and app.options that