question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

react proxy does not work

See original GitHub issue

Hi i am facing issue with react proxy … Actually i am accessing files from other port The proxy works for “/” but not for any other url like “/currentpost/images/” my proxy code is

  "proxy": {
    "/api/*": {
      "target": "http://localhost:5000"
    },
    "/currentPost/images/*" : {
      "target" : "http://localhost:5000"
    },
    "/images/*": {
      "target": "http://localhost:5000"
    }

}

prob1

and my proxy code in package js file is ps://user-images.githubusercontent.com/35171108/46656606-dfe41f80-cbc7-11e8-9d1c-9d1713814ca8.PNG)

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
ghengeveldcommented, Oct 16, 2018

Perhaps this will help you: https://github.com/facebook/create-react-app/issues/5441#issuecomment-429981692

My src/setupProxy.js looks like this now (simplified):

app.use(
  proxy("/rootpath", {
    target: "https://example.org",
    changeOrigin: true,
    onProxyReq(proxyReq) {
      if (proxyReq.getHeader("origin")) {
        proxyReq.setHeader("origin", "https://example.org")
      }
    },
    pathRewrite: { "^/rootpath": "" },
    logLevel: "debug",
  })
)

I recommend setting the logLevel so you’ll be aware when a route is or isn’t proxied.

2reactions
Pier2208commented, Oct 16, 2018

hey

@USMAN378 @Timer I have struggled quite some time with the exact same problem, but then I removed the wild card * and everyhting works fine again. so try: app.use(proxy(‘/api/’, { target: ‘http://localhost:5000’ }))

Pierrick

Read more comments on GitHub >

github_iconTop Results From Across the Web

proxy not working for react and node - Stack Overflow
25 Answers 25 · Delete package-lock.json and node_modules in React app · Turn off React Terminal and npm install all dependencies again on...
Read more >
Proxy not working · Discussion #10149 · facebook/create-react ...
I've used "proxy": "http://localhost:8080" in my package.json for numerous other CRA projects to connect to my Express backend with no issues.
Read more >
Proxy does not work with the React build version - JavaScript
Proxy works with 'npm start' but does not work with the React build version npm start version package.json { "name"…
Read more >
React — How To Proxy To Backend Server - Medium
If you change the port in the proxy value in the package.json proxying calls to the API will not work. Create React App...
Read more >
Why you should use a proxy server with Create React App
CRA supports proxying to mitigate or entirely eliminate these issues. In this article, we will discuss what a proxy server is, why you ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found