Launch 2 servers on 2 different port

rails
server

#1

I’m trying to launch rails and webpack with foreman and it fails.

Here is my Procfile

web: bundle exec rails s -p $PORT -b $IP
webpacker: ./bin/webpack-dev-server --inline true --hot true

And my webpacker.yml

  dev_server:
    host: 0.0.0.0
    port: 8081
    https: false

Rails run with HTTPS on 8080, and the webpack with HTTP on 8081 :

al1andre:~/workspace/todo_list (master) $ foreman start
09:28:07 web.1       | started with pid 1682
09:28:07 webpacker.1 | started with pid 1683
09:28:07 webpacker.1 | yarn run v0.27.5
09:28:08 webpacker.1 | $ "/home/ubuntu/workspace/todo_list/node_modules/.bin/webpack-dev-server" "--progress" "--color" "--config" "/home/ubuntu/workspace/todo_list/config/webpack/development.js" "--inline" "true" "--hot" "true"
09:28:11 webpacker.1 |  10% building modules 3/3 modules 0 active                                         
09:28:11 webpacker.1 | Project is running at http://0.0.0.0:8081/
09:28:11 webpacker.1 | webpack output is served from http://0.0.0.0:8081/packs/
09:28:11 webpacker.1 | Content not from webpack is served from /home/ubuntu/workspace/todo_list/public/packs
09:28:11 webpacker.1 | 404s will fallback to /index.html
Hash: 0b7fc436eb60e85a93ae                                                              
09:28:16 web.1       | => Booting Puma
09:28:16 webpacker.1 | Version: webpack 3.4.1
09:28:16 web.1       | => Rails 5.1.2 application starting in development on http://0.0.0.0:8080
09:28:16 webpacker.1 | Time: 4969ms
09:28:16 web.1       | => Run `rails server -h` for more startup options
09:28:16 webpacker.1 |               Asset       Size  Chunks                    Chunk Names
09:28:16 web.1       | Puma starting in single mode...
09:28:16 webpacker.1 | server_rendering.js    3.01 MB       0  [emitted]  [big]  server_rendering
09:28:16 web.1       | * Version 3.9.1 (ruby 2.4.1-p111), codename: Private Caller
09:28:16 webpacker.1 |      application.js    3.01 MB       1  [emitted]  [big]  application
09:28:16 web.1       | * Min threads: 5, max threads: 5
09:28:16 webpacker.1 |      hello_react.js    2.96 MB       2  [emitted]  [big]  hello_react
09:28:16 web.1       | * Environment: development
09:28:16 webpacker.1 |       manifest.json  204 bytes          [emitted]         
09:28:16 web.1       | * Listening on tcp://0.0.0.0:8080
09:28:16 webpacker.1 |   [50] (webpack)/hot/log.js 1.04 kB {0} {1} {2} [built]
09:28:16 web.1       | Use Ctrl-C to stop
09:28:16 webpacker.1 |   [85] (webpack)/hot/emitter.js 77 bytes {0} {1} {2} [built]
09:28:16 webpacker.1 |  [124] (webpack)-dev-server/client?http://0.0.0.0:8081 5.83 kB {0} {1} {2} [built]
09:28:16 webpacker.1 |  [171] (webpack)/hot nonrecursive ^\.\/log$ 170 bytes {0} {1} {2} [built]
09:28:16 webpacker.1 |  [173] (webpack)/hot/dev-server.js 1.61 kB {0} {1} {2} [built]
09:28:16 webpacker.1 |  [174] (webpack)/hot/log-apply-result.js 1.31 kB {0} {1} {2} [built]
09:28:16 webpacker.1 |  [175] ./node_modules/react/react.js 56 bytes {0} {1} {2} [built]
09:28:16 webpacker.1 |  [190] ./node_modules/react-dom/index.js 59 bytes {0} {1} {2} [built]
09:28:16 webpacker.1 |  [271] ./app/javascript/components ^\.\/.*$ 160 bytes {0} {1} [built]
09:28:16 webpacker.1 |  [285] multi (webpack)-dev-server/client?http://0.0.0.0:8081 webpack/hot/dev-server ./app/javascript/packs/application.js 52 bytes {1} [built]
09:28:16 webpacker.1 |  [286] ./app/javascript/packs/application.js 730 bytes {1} [built]
09:28:16 webpacker.1 |  [287] multi (webpack)-dev-server/client?http://0.0.0.0:8081 webpack/hot/dev-server ./app/javascript/packs/hello_react.jsx 52 bytes {2} [built]
09:28:16 webpacker.1 |  [288] ./app/javascript/packs/hello_react.jsx 739 bytes {2} [built]
09:28:16 webpacker.1 |  [290] multi (webpack)-dev-server/client?http://0.0.0.0:8081 webpack/hot/dev-server ./app/javascript/packs/server_rendering.js 52 bytes {0} [built]
09:28:16 webpacker.1 |  [291] ./app/javascript/packs/server_rendering.js 299 bytes {0} [built]
09:28:16 webpacker.1 |     + 277 hidden modules
09:28:16 webpacker.1 | webpack: Compiled successfully.

But the navigator cannot reach http://isomorphicreactjs-al1andre.c9users.io:8081/ ; it says it’s not accessible (Rails is).

Any idea of what I’m doing wrong ? I’m on a free plan, maybe multiple port is not allowed ?


#2

Ok, I have more informations.

When I’m running in console curl http://0.0.0.0:8081/packs/hello_react.js it returns the JS file, but when typing in a browser, I get a Invalid Host header on the web page.

Thanks to this post, I could solve it.

I had to modify my Procfile as this to make it work :

web: bundle exec rails s -p $PORT -b $IP
webpacker: ./bin/webpack-dev-server --inline true --hot true --public $C9_HOSTNAME