Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

webpack-dev-server over HTTPS #181

Closed
daninfpj opened this issue Oct 30, 2018 · 6 comments
Closed

webpack-dev-server over HTTPS #181

daninfpj opened this issue Oct 30, 2018 · 6 comments

Comments

@daninfpj
Copy link

I'm using puma-dev to proxy to port 8080 where webpack-dev-server is running.

If I access the site at https://domain.test the page loads, except the webpack-dev-server connection to https://domain.test:8080/sockjs-node/info?t=1540932421825 which gets a ERR_CONNECTION_CLOSED. However it works at http://domain.test:8080/sockjs-node/info?t=1540932421825.

If I run webpack-dev-server in HTTPS mode, the connection at https://localhost:8080/sockjs-node/info?t=1540932421825 works but through puma-dev there's an error:

http: proxy error: read tcp 127.0.0.1:63458->127.0.0.1:8080: read: connection reset by peer

How can I get it working with the socket connection through HTTPS?

@wildjcrt
Copy link

@daninfpj I've success with this settings. Maybe you can try it out.

In config/webpacker.yml, just use default. Remember to keep https: false.

Below is part of my config/webpacker.yml.

dev_server:
  https: false
  host: localhost
  port: 3035
  public: localhost:3035

Run this command for webpack domain.

$ echo 3035 > ~/.puma-dev/webpack.domain

Last step, set up you rails development environment. In config/environments/development.rb, set up config.action_controller.asset_host = '//webpack.domain.test'.

Done. :)

@daninfpj
Copy link
Author

daninfpj commented Feb 5, 2019

@wildjcrt you might be referring to Rails’ webpacker, I'm actually using a standalone webpack-dev-server but I think you pointed me in the right direction. This is the config that worked for me:

entry: [
    `webpack-dev-server/client?https://domain.test`,
…
devServer: {
…
    https: false,
    public: domain.test,
  }

@Eric-Guo
Copy link

Leave an additional comment here, if you change https: true for the local https app like https://your-app.test/, need access https://your-app.test:3035/sockjs-node/info?t=1564015123119 and access the certificate manually as it's self-signed.

barrywoolgar added a commit to barrywoolgar/puma-dev that referenced this issue Apr 10, 2020
This is based on code provided by @daninfpj in puma#181 and uses Puma-dev to resolve a common configuration issue when developing modern Rails apps that need/want to use the Webpack Dev Server over SSL.
@barrywoolgar
Copy link
Contributor

@wildjcrt Thanks for your example, it almost worked for me but I found I had to use public: webpack.domain.test (without the port number) to avoid console errors about sockjs-node/info. I made a PR to add an updated version of your example to the README.

nonrational pushed a commit that referenced this issue Apr 10, 2020
This is based on code provided by @daninfpj in #181 and uses Puma-dev to resolve a common configuration issue when developing modern Rails apps that need/want to use the Webpack Dev Server over SSL.
@barrywoolgar
Copy link
Contributor

barrywoolgar commented Jun 9, 2020

njradford: suggestion for using this workaround while also serving up sprockets assets? It seems to fix the webpack issue but disrupt the existing rails assets.

@njradford Ah that is a problem! I don't have access to a mixed sprockets/webpacker project to test this at the moment, but I'm guessing requests for sprockets assets are being directed to the webpack dev server.

If so, I wonder if it's possible to use the contentBase configuration option to reconnect those requests to the on-disk sprockets assets? Though without a request passing through the Rails app, I guess there's nothing to trigger those assets to be (re)generated.

@barrywoolgar
Copy link
Contributor

Another solution could be this suggestion to use a proc for asset_host which looks rather hacky but might just be crazy enough to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants