Issue with proxy
See original GitHub issueI have an issue when trying to use a proxy. I have a server.js file with express that is using port 5000, and im running CRA in port 3000. Im pretty sure im using CRA v2+ (actually I used the command create react app just today)
Initially my package json (in the client) had this line
"proxy": "http://localhost:5000"
I deleted and replace it with the setupProxy (I installed the npm dependency on my client package.json) file with the following:
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use(proxy('/api/', { target: 'http://localhost:5000/' }));
};
The file its placed inside appRootFolder/client/src.
When I run the app I noticed that im getting 404 in the routes
But if I add again the proxy line in my package json, its working
The proxy middleware is running right? Because it shows the complete route though strangely is not working. Am I missing something? This is the route in my server.js
app.get('/api/site/site_data',(req,res)=>{
Site.find({}, (err, site) => {
if(err) return res.status(400).send(err);
res.status(200).send(site[0].siteInfo)
});
});
Issue Analytics
- State:
- Created 5 years ago
- Comments:5 (4 by maintainers)
Meaning
api/*
matches:api/test
api/foo
But does not match:
api/foo/bar
Using
api/**
will match:api/test
api/foo
api/foo/bar
😄
See https://github.com/isaacs/node-glob for a more full explanation.
Ah, then yes the
**
will fix it.**
says “all subpaths”,*
is only a one-level path.