Я реагирую с приложением express и node.js, и получаю ошибку CORS при удалении, но не при post / get ... вот код node.js:
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", "GET, PUT, POST, DELETE, OPTIONS");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept, Authorization");
bodyParser.json()
next();
});
app.delete("api/delete/item", (req, res) => {
console.log(req.body.id)
})
и часть React:
import React from 'react'
import { Button } from 'reactstrap'
import axios from 'axios'
const Delete = props => {
const id = props.id
const remove = () => {
axios.delete('http://localhost:5000/api/delete/item', { id: id})
.then(res => console.log(res))
}
return (
<Button onClick={() => remove()} >Delete</Button>
)
}
export default Delete
и я забыл, фактическая ошибка:
localhost/:1 Access to XMLHttpRequest at 'http://localhost:5000/api/delete/item' from origin 'http://localhost:3000' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.