I have data in a local JSON
file; to query that data, I'm using axios-mock-adapter
. But for some reason, it's giving 404 not found
. Not sure what I'm missing
Exact error: GET http://localhost:3000/api/results 404 (Not Found)
I have created a db folder
with all the files below.
mock.js
file
const MockAdapter = require('axios-mock-adapter');
const axios = require('axios');
const Mock = new MockAdapter(axios.create());
export default Mock;
index.js
file
import Mock from './mock';
import './db/database';
Mock.onAny().passThrough();
database.js
file
import Mock from "../mock";
const database = {
results: {
books: [
name: "loren ipsum",
],
},
};
Mock.onGet("/api/results").reply((config) => {
const response = database.results;
console.log("mock results", response);
return [200, response];
});
and then in my components:
I am querying it like this:
const [books, setBooks] = useState([]);
useEffect(() => {
async function fetchData() {
const request = await axios.get("/api/results").then((response) => {
console.log("res", response.data);
console.log("request", request);
setBooks(request);
});
return request;
}
fetchData();
}, []);