I have a react frontend that is making a request to my nodejs express backend. Cors is enabled like so
import express, { Express } from 'express'
import cors from 'cors'
import todoRoutes from './routes/router'
const app: Express = express()
const PORT: string | number = process.env.PORT || 4000
app.use(cors())
app.use(express.json())
However, when I make the request I nonetheless get this error back
index.js:1 Error: Network Error
at createError (createError.js:16)
at XMLHttpRequest.handleError (xhr.js:91)
My request looks like this
const addTodo = async (
formData: ITodo
): Promise<void> => {
const todo: Omit<ITodo, '_id'> = {
name: formData.name,
text: formData.text,
status: false,
createdAt: formData.createdAt
}
return await axios.post(
api + '/add-todo', {
headers: {
'Content-Type': 'application/json',
'Accept': 'application/json'
},
todo
}
).then((response => {
console.log(response)
}
), (error) => {
console.error(error)
throw new Error(error)
})
In the Network tab on devtools it just says for the status
blocked:other