0

I followed the instructions here https://www.fullstackreact.com/articles/how-to-get-create-react-app-to-work-with-your-rails-api/ to create a react app with a rails backend. Basically, I have the rails api proxied through localhost:3001, as specified here in package.json:

{
"name": "fidirect",
"version": "0.1.0",
"private": true,
"proxy": "http://localhost:3001/",
"devDependencies": {
"enzyme": "2.4.1",
"react-addons-test-utils": "15.4.0",
"react-scripts": "0.8.5"
}, 

I have foreman in the gemfile, and a procfile that looks like this:

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

I have a rake task to handle booting both servers, in lib/tasks/start.rake, that looks like this:

task :start do
  exec 'foreman start -p 3000'
end

All of this is exactly as specified in the README for the sample app, but when I hit rake start, I see this error:

 started with pid 24179
 05:24:10 api.1  | started with pid 24180
 05:24:13 web.1  |
 05:24:13 web.1  | > fidirect@0.1.0 start /home/adt6261-
 133051/code/FiDirect/client
 05:24:13 web.1  | > react-scripts start
 05:24:13 web.1  |
 05:24:22 web.1  | Attempting to bind to HOST environment variable: 
 138.68.11.226
 05:24:22 web.1  | If this was unintentional, check that you haven't 
 mistakenly set it in your shell.
 05:24:22 web.1  | Learn more here: 
 05:24:22 web.1  |
 05:24:22 web.1  | Something is already running on port 3000.
 05:24:23 api.1  | => Booting Puma
 05:24:23 api.1  | => Rails 5.1.4 application starting in development
 05:24:23 api.1  | => Run `rails server -h` for more startup options
 05:24:23 api.1  | Puma starting in single mode...
 05:24:23 api.1  | * Version 3.11.2 (ruby 2.3.1-p112), codename: Love Song
 05:24:23 api.1  | * Min threads: 5, max threads: 5
 05:24:23 api.1  | * Environment: development
 05:24:23 api.1  | * Listening on tcp://138.68.11.226:3001
 05:24:23 api.1  | Use Ctrl-C to stop
 05:24:23 web.1  | exited with code 0
 05:24:23 system | sending SIGTERM to all processes
 05:24:23 api.1  | - Gracefully stopping, waiting for requests to finish
 05:24:23 api.1  | === puma shutdown: 2018-02-07 05:24:23 +0000 ===
 05:24:23 api.1  | - Goodbye!
 05:24:23 api.1  | Exiting
 05:24:23 api.1  | terminated by SIGTERM 

Has anyone encountered a similar issue before/ know what the problem might be? Any input greatly appreciated.

Dan Lowe
  • 51,713
  • 20
  • 123
  • 112
adam tropp
  • 674
  • 7
  • 22

2 Answers2

1

In your terminal run lsof -wni tcp:3000 and you should be able to see the service running on that port, then kill -9 <service number>

An alternative is using a different port for y service

Fabrizio Bertoglio
  • 5,890
  • 4
  • 16
  • 57
  • If this answer was solving your problem, you can find more info in the below link for deleting the running server. https://stackoverflow.com/questions/15072846/server-is-already-running-in-rails – Hamdi Bayhan Feb 07 '18 at 08:46
  • This seems to be a linux command. Do you know an equivalent one that works on windows? I have tried netstat with various combinations, but non has worked so far. – adam tropp Feb 07 '18 at 18:03
0

I think you may have answered your own question.

Do you have any other apps that are running/using that port? I'd suggest maybe listing existing processes using ps and then spotting to see if there is another instance of your app running.

Nonetheless, best of luck!

Brian Zhou
  • 574
  • 6
  • 15