我正在尝试从 Service Workers 入手并阅读您需要拥有 ssl 证书。
我有一个 AngularJS 1.x 应用程序和一个 Node Express 后端,我都独立运行,所以我使用 grunt serve
在端口 8443
上运行前端我用node app.js
运行 7443
上的 express .
note: I'm doing this on macOS
我使用了有关如何在使用 Grunt 的项目上设置 https 的指南:here
openssl genrsa -out livereload.key 1024
openssl req -new -key livereload.key -out livereload.csr
openssl x509 -req -in livereload.csr -signkey livereload.key -out livereload.crt
Gruntfile.js
options: {
protocol: 'https', // or 'http2'
port: 8443,
hostname: '0.0.0.0',
key: grunt.file.read('livereload.key'),
cert: grunt.file.read('livereload.crt')
},
node app.js
var privateKey = fs.readFileSync('../livereload.key', 'utf8');
var certificate = fs.readFileSync('../livereload.crt', 'utf8');
var credentials = {key: privateKey, cert: certificate};
httpsServer.listen(7443, config.ip, function () {
console.log('Express server listening on %d, in %s mode', 7443, app.get('env'));
});
两者都没有错误,前端确实提示连接不是私有(private)的。当我的前端尝试访问 express 服务器上的端点时,我收到以下信息;
OPTIONS https://localhost:7443/api/census/general net::ERR_INSECURE_RESPONSE
有人可以帮助解决我的这个问题吗。
最佳答案
您已经创建了一个自签名证书,该证书适合开发和测试,但被认为不安全 一般用途。与从信誉良好的第三方购买的 SSL 证书不同,自签名证书在默认情况下不受信任。
您需要告诉您的操作系统明确信任该证书。我不熟悉 Mac 操作系统,但是 this question之前在 SuperUser 上回答过。
关于javascript - Grunt Node 和 Express 本地开发 HTTPS 证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41203718/