app.js
</span>
No "Access-Control-Allow-Origin" header
Access-Control-Allow-Headers
//
axios.post(`http://localhost:8089/api/test`, null)
.then(response => {
console.log(response.data);
});
find a solution
app.js
</span>
No "Access-Control-Allow-Origin" header
Access-Control-Allow-Headers
//
axios.post(`http://localhost:8089/api/test`, null)
.then(response => {
console.log(response.data);
});
find a solution
that's because all your code 1, including the options request browser, will pre-check before the non-simple request, and you haven't processed it, so you won't send the post request
A solution has been found
the options request needs to be processed
router.options('/api/test/', (ctx, next) => {
ctx.set('Access-Control-Allow-Origin', '*');
ctx.set('Access-Control-Allow-Headers', 'Content-Type, Content-Length, Authorization, Accept, X-Requested-With , myheader');
ctx.set('Access-Control-Allow-Methods', 'PUT, POST, GET, DELETE, OPTIONS');
ctx.status = 200;
return;
});
as for the problem of cross-domain without setting the request header, the reason is that my current cross-domain request is a simple request and does not send an options, in advance, so the cross-domain is still successful.
Previous: Cookie generated after the online introduction of the js plug-in
Next: The less, configuration referenced in the react project reported an error and asked for help.