Skip to content

Issue with https #612

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

Closed
Radzhab opened this issue Aug 3, 2017 · 2 comments
Closed

Issue with https #612

Radzhab opened this issue Aug 3, 2017 · 2 comments

Comments

@Radzhab
Copy link

Radzhab commented Aug 3, 2017

ps. sorry for my english.

I have site that work over https. I add changes to webpacker to work with ssl.

image

development.js

// Note: You must restart bin/webpack-dev-server for changes to take effect

const merge = require('webpack-merge')
const sharedConfig = require('./shared.js')
const { settings, output } = require('./configuration.js')

module.exports = merge(sharedConfig, {
  devtool: 'cheap-eval-source-map',

  output: {
    pathinfo: true
  },

  devServer: {
    https: true,
    clientLogLevel: 'none',
    host: settings.dev_server.host,
    port: settings.dev_server.port,
    contentBase: output.path,
    publicPath: output.publicPath,
    compress: true,
    headers: { 'Access-Control-Allow-Origin': '*' },
    historyApiFallback: true,
    watchOptions: {
      ignored: /node_modules/
    },
    stats: {
      errorDetails: true
    }
  }
})

But its raise error in browser. Its download applictions js over http? Why so?
Mixed Content: The page at 'https://localhost:3000/' was loaded over HTTPS, but requested an insecure script 'http://localhost:8080/packs/application.js'. This request has been blocked; the content must be served over HTTPS.

server puma.

@rossta
Copy link
Member

rossta commented Aug 3, 2017

In your case, you'll want to instruct your browser to trust the self-signed certificate that ships with webpack-dev-server. For Chrome on Mac, something like this might work for you:

$ sudo security add-trusted-cert -d -r trustRoot -k /Library/Keychains/System.keychain ~/path/to/app/node_modules/webpack-dev-server/ssl/server.pem

In some cases, you may need to create a separate self-signed SSL certificate instead. There are lots of posts on the web about how to do this and for how to get some/most browsers to trust the certificate.

To make webpack dev server config aware of the certificate, I'm using something similar to the config here:

// config/webpack/local-ssl.js
const { resolve  } = require('path');
const { readFileSync } = require('fs');

module.exports = {
  cert: readFileSync(resolve('path', 'to', 'localhost-self-signed.pem'), 'utf8')
};
// config/webpack/development.js
const { cert } = require('./local-ssl.js')
const https = { key: cert, cert: cert }

module.exports = merge(sharedConfig, {
  // ...
  devServer: {
    // ...
    https: https,
  },
//...

I may open a PR to add this to the README, but in the meantime, I hope that's helpful.

@gauravtiwari
Copy link
Member

thanks @rossta 🍰

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

3 participants