配置文件中的webpack4 webpack-dev-server ssl

时间:2018-10-02 21:41:33

标签: ssl webpack https webpack-dev-server webpack-4

this cli command之后:

messages    
('400: {\r\n'
 '  "error": {\r\n'
 '    "code": "SearchWithOrderBy",\r\n'
 '    "message": "The query parameter \'$orderBy\' is not supported with '
 '\'$search\'.",\r\n'
 '    "innerError": {\r\n'
 '      "request-id": "1416dd7c-81o4-4b52-953d-ab23c0933be9",\r\n'
 '      "date": "2018-10-02T11:30:12"\r\n'
 '    }\r\n'
 '  }\r\n'
 '}')

我想在我的webpack.config文件中添加文件。类似:

npm run webpack-dev-server --mode development --open --cert=../../ssl/server.pem --key=../../ssl/server.pem

1 个答案:

答案 0 :(得分:2)

这个问题在我试图解决时在浏览器中打开了一个小时...最终我成功了..希望我可以节省别人和一个小时:)

link to reference

module.exports = {

    ...
    devServer: {
        https: {
            key: fs.readFileSync('/path/to/server.key'),
            cert: fs.readFileSync('/path/to/server.crt'),
            ca: fs.readFileSync('/path/to/ca.pem'),
        }
    }
    ...
}

可能需要3个小时..如果您需要生成自己的证书..而Chrome会中断。

To generate your dev certificate

openssl req \
    -newkey rsa:2048 \
    -x509 \
    -nodes \
    -keyout server.pem \
    -new \
    -out server.pem \
    -subj /CN=localhost \
    -reqexts SAN \
    -extensions SAN \
    -config <(cat /System/Library/OpenSSL/openssl.cnf \
        <(printf '[SAN]\nsubjectAltName=DNS:localhost')) \
    -sha256 \
    -days 3650