food-lookup-demo-rails icon indicating copy to clipboard operation
food-lookup-demo-rails copied to clipboard

Proxy not working

Open pkpp1233 opened this issue 9 years ago • 6 comments
trafficstars

Tried on react-scripts version 0.2.3 and 0.7.0. In both cases, proxy doesn't work and API calls go to localhost:3000 instead of localhost:3001. Anyone else run into this?

pkpp1233 avatar Nov 11 '16 17:11 pkpp1233

Hi @pkpp1233,

Thanks for your patience. Updating the repo now to 0.7.0. Still, I'm not sure what you're running into -- on a fresh install of master I don't have any issues. Were you trying this on a clean version of master or your own fork? If this is still a problem, would you mind providing more info?

acco avatar Dec 01 '16 22:12 acco

@acco @pkpp1233 I seem to have a similar issue (maybe?) my proxy runs on port 3100 rather than 3001? Not really sure why as my Procfile is:

web: cd client && npm start
api: bundle exec rails s -p 3001

And the output of rake start is:

Running via Spring preloader in process 31341
16:21:17 web.1  | started with pid 31342
16:21:17 api.1  | started with pid 31343
16:21:18 web.1  |
16:21:18 web.1  | > [email protected] start /Users/will/Labs/ruby/food-demo/client
16:21:18 web.1  | > react-scripts start
16:21:18 web.1  |
16:21:19 web.1  | Starting the development server...
16:21:19 web.1  |
16:21:19 api.1  | => Booting Puma
16:21:19 api.1  | => Rails 5.0.1 application starting in development on http://localhost:3001
16:21:19 api.1  | => Run `rails server -h` for more startup options
16:21:19 api.1  | Puma starting in single mode...
16:21:19 api.1  | * Version 3.7.0 (ruby 2.2.2-p95), codename: Snowy Sagebrush
16:21:19 api.1  | * Min threads: 5, max threads: 5
16:21:19 api.1  | * Environment: development
16:21:19 api.1  | * Listening on tcp://0.0.0.0:3100
16:21:19 api.1  | Use Ctrl-C to stop
16:21:24 web.1  | Compiled successfully!
16:21:24 web.1  |
16:21:24 web.1  | The app is running at:
16:21:24 web.1  |
16:21:24 web.1  |   http://localhost:3000/
16:21:24 web.1  |
16:21:24 web.1  | Note that the development build is not optimized.
16:21:24 web.1  | To create a production build, use npm run build.

So I changed my client/package.json to reflect this as:

{
  "name": "client",
  "version": "0.1.0",
  "private": true,
  "proxy": "http://localhost:3100/",
  "devDependencies": {
    "react-scripts": "0.8.5"
  },
  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  }
}

And it works… ¯\_(ツ)_/¯

willwright82 avatar Feb 03 '17 16:02 willwright82

Hi @willwright82 -- hmmm. I noticed you're using Puma. On the one hand, it says this:

16:21:19 api.1  | => Rails 5.0.1 application starting in development on http://localhost:3001

But then later it says this:

16:21:19 api.1  | * Listening on tcp://0.0.0.0:3100

As you say: ¯\_(ツ)_/¯

The -p flag may not be a valid way to set the port for Puma and Puma is using 3100 by default

acco avatar Feb 08 '17 22:02 acco

I updated to Rails 5 and tested everything again -- still works fine for me

acco avatar Feb 08 '17 22:02 acco

Thanks @acco — Will play around with it and see. 🤔

willwright82 avatar Feb 09 '17 10:02 willwright82

If you haven't solved this yet, as I remember, the version of Puma (3.4?) that originally shipped with Rails 5.0.1 did not allow you to override the port number correctly. There were actually a couple of buggy versions of Puma as this kept coming back.....again, as I remember. It has been a while since I tried Rails 5.0

I just built the project from scratch with Rails 5.1.3 and Puma 3.7 and everything works correctly.

michael-reeves avatar Aug 23 '17 18:08 michael-reeves