I’m facing an issue in my react application where I have created setupProxy.js file inside src folder. In that I have multiple proxy’s one should work for oidc login & another proxy will work as backend port (9098). Instead of passing this 9098 proxy in package.json file .Do to testing propose I have added inside setupProxy file.
- Package.json – > “proxy” : “http://localhost:9098”
Note: Below I have added setupProxy code/ proxy’s.
const { createProxyMiddleware } = require('http-proxy-middleware');
module.exports = function (app) {
app.use(
'/bizcomp/restservices/v1/auth', // Match the API path you want to proxy
createProxyMiddleware({
target: 'https://bizcomp.dev.att.com', // Target OIDC server
changeOrigin: true, // Modify the origin header to the target URL
pathRewrite: {
'^/bizcomp/restservices/v1/auth': '/bizcomp/restservices/v1/auth', // Rewrite the URL path if necessary
},
onProxyReq: (proxyReq, req, res) => {
// Optional: Add any custom headers to the proxy request
proxyReq.setHeader('X-Special-Proxy-Header', 'foobar');
},
onProxyRes: (proxyRes, req, res) => {
// Optional: Manipulate the proxy response before sending it back to the client
proxyRes.headers['x-added'] = 'foobar'; // Example of adding a custom header to the response
},
logLevel: 'debug', // Set to 'debug' to see detailed logs of the proxy activity
})
);
app.use(
'/bizcomp/restservices/v1/service', // Match the exact path
createProxyMiddleware({
target: 'http://localhost:9098', // Backend server URL
changeOrigin: true, // Modify the origin header to match the target
logLevel: 'debug', // Enable detailed logging for debugging
pathRewrite: { '^/bizcomp/restservices/v1/service': '' }, // Remove the base path if needed
followRedirects: true, // Follow HTTP 3xx responses
})
);
};
http://localhost:3000/bizcomp/restservices/v1/service/systemtools/getActiveAnnouncements
–> This is api which we are using in our application
This is error in network. Its getting 404 error (Not Found)
{
"timestamp": "2024-09-02T18:56:18.883+00:00",
"status": 404,
"error": "Not Found",
"path": "/systemtools/getActiveAnnouncements"
}