I need to test the app from a mobile phone, and file is checked into Git where other developers access it. How do I dynamically set the host name to the IP address of the server? I tried
webpacker.yml
development:
dev_server:
host: <%= Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address %>
It gave the error
Error: getaddrinfo ENOTFOUND <%= Socket.ip_address_list.find { |ai| ai.ipv4? && !ai.ipv4_loopback? }.ip_address %>
I tried renaming the file to webpackager.yml.erb but it gave the error
Webpack dev_server configuration not found in .../config/webpacker.yml.
I ran into the same issue and embedded Ruby within webpacker.yml doesn't appear to be possible.
However, in development mode, you can override webpack-dev-server configuration values via environmental variables. Example:
WEBPACKER_DEV_SERVER_HOST=example.com ./bin/webpack-dev-server
If you're using Foreman, add the command to the relevant Procfile, such as:
webpack: WEBPACKER_DEV_SERVER_HOST=0.0.0.0 ./bin/webpack-dev-server
web: rails s -b 0.0.0.0
More specifically, for your case, something like:
WEBPACK_DEV_SERVER_HOST=$(ruby -e "require 'socket'; Socket.ip_address_list.detect{|intf| intf.ipv4_private?}.inspect_sockaddr") ./bin/webpack-dev-server
References:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With