- when use [ Axios or Fetch ] to make operation on [couchdb]
- using localhost: request is pending
- and when test with postman the same problem
first solution is to use 127.0.0.1 instead of localhost
- it works in postman but with the frontend request gives me CORS Error
My Envirnoment
- using coushDB in docker-composer.yml
- frontEnd is reactjs
- http library is Axios
version: '3'
services:
couchserver:
image: couchdb
ports:
- '5984:5984'
environment:
- COUCHDB_USER=admin
- COUCHDB_PASSWORD=password
# address binding
- COUCHDB_BIND_ADDRESS= 0.0.0.0
volumes:
- ./dbdata:/opt/couchdb/data
- Error Show is
Access to XMLHttpRequest at 'http://admin:password@127.0.0.1:5984/taskboard1' from origin 'http://localhost:5983' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource.
- Frontend code
// put request to create a new task
export const createTaskBoard = createAsyncThunk(
'tasks/createTask',
async (taskBoardBody: taskBoard) => {
// using axios for put request
const options = {
headers: {
'Content-type': 'application/json',
'Access-Control-Allow-Origin': '*',
},
};
console.log('here test');
const { data, status } = await axios.put<taskBoard>(
'http://admin:password@127.0.0.1:5984/taskboard1',
taskBoardBody,
options,
);
return data;
},
);