'I am deploying my react app in tomcat server but giving 404
I am not able to access the API from localhost 9763 and my tomcat run localhost8080 I am using HTTP-proxy-middleware but it's not working
Proxysetup.js
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
createProxyMiddleware({
target: 'http://localhost:9763',
changeOrigin: true,
})
);
};
** fetch API**
useEffect(() => {
const getData = () => {
//showLoader();
axios
.get("api/getPlaylist?Playlist=2016804", {
headers: {
"Access-Control-Allow-Origin": "*",
Accept: "application/json",
"Content-Type": "application/json",
},
auth: {
username: "admin",
password: "password",
},
parms: {
Playlist: "all",
},
})
.then((response) => {
setIsLoading(true);
// console.log(response.data);
//console.log(typeof response.data);
//this.setState({ Data: [...Object.values(response.data).flat()] });
setComments([...Object.values(response.data).flat()]);
//console.log([...Object.values(response.data).flat()]);
})
.catch((error) => {
// this.setState({ error: 'unable to fetch URL' });
error("unable to fetch URL", error);
// console.log(error.response);
});
};
getData();
setInterval(() => {
getData();
}, 5000);
}, []);
when i build and deployed in Apache api re not fetching
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|