Answer the question
In order to leave comments, you need to log in
Why can't I send a POST request via Axios?
Server:
const corsConfig = {
origin: `http://${host}`,
optionsSuccessStatus: 200,
credentials: true,
};
route.post('/login', cors(corsConfig), async (req, res) => {
...
}
res.set('Access-Control-Allow-Origin', `http://${host}`);
this.$axios.post(
'/login',
{
mail: this.email,
pass: this.password,
remember: this.remember,
reToken: token,
},
{ withCredentials: true },
);
Answer the question
In order to leave comments, you need to log in
The host variable on the server must be localhost for this to work, not the server host (or whatever you have).
Origin can be checked dynamically if you are polled by more than 1 host:
https://github.com/expressjs/cors#configuring-cors... You
can also pass RegExp or an array of strings/RegExp there:
https://github.com/ expressjs/cors#configuration-options
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question