My error message: "Failed to load http://localhost:8080/db: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:3000' is therefore not allowed access."
My front end server is running on localhost:3000
componentDidMount() {
axios
.get('http://localhost:8080/db')
.then(response => console.log(response))
.catch(err => console.log(err));
}
This is in my express file:
app.use((req, res, next) => {
res.setHeader('Access-Control-Allow-Origin', '*');
res.setHeader(
'Access-Control-Allow-Headers',
'Origin, X-Requested-With, Content-Type, Accept'
);
res.setHeader(
'Access-Control-Allow-Methods',
'POST, GET, PATCH, DELETE, OPTIONS'
);
next();
});