[Docs] Proxying API Requests in Development / Configuring the Proxy Manually - not working solution
See original GitHub issueThe suggested code:
const proxy = require('http-proxy-middleware');
module.exports = function(app) {
app.use(
'/api',
proxy({
target: 'http://localhost:5000',
changeOrigin: true,
})
);
};
doesn’t work. It fails with this error:
proxy is not a function
Also, it’s not clear at all how to use this proxy.
How to enable one proxy for testing (local mock server) and another for development?
Issue Analytics
- State:
- Created 4 years ago
- Reactions:2
- Comments:10
Top Results From Across the Web
Proxying API Requests in Development - Create React App
The development server will only attempt to send requests without text/html in its Accept header to the proxy.
Read more >Configuring setupProxy.js using http-proxy-middleware
I have tried prepending my API URL within my fetch call with 'https://cors-anywhere.herokuapp.com/' ( https://github.com/Rob--W/cors-anywhere/ ) ...
Read more >Configure a Proxy in React - James Q Quick
The Solution. To solve this problem, we can configure a proxy in the package.json file of the React project. This allows the app...
Read more >Proxying API Requests in Development - Gatsby
This way, when you fetch('/api/todos') in development, the development server will recognize that it's not a static asset, and will proxy your request...
Read more >API proxy configuration reference | Apigee X - Google Cloud
View Apigee Edge documentation. As a developer working with Apigee, your primary development activities involve configuring API proxies that function as ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Let me share my solution.
I created
src/setupProxy.js
with the following content:and added these two extra lines in my
package.json
:Now when I launch the app with the
--mock
parameter, it connects to the locally running mock server, and if leave it out, the client is connecting to our dev server.This is an excerpt from the
scripts
section of mypackage.json
:This issue has been automatically closed because it has not had any recent activity. If you have a question or comment, please open a new issue.