SSR使用HTTPS

1.安装 npm i browser-sync

  1. 再angular.json里配置
bash 复制代码
        "serve-ssr": {
          "builder": "@nguniversal/builders:ssr-dev-server",
          "options": {
            "ssl": true,
            "sslCert": "./node_modules/browser-sync/certs/server.crt",
            "sslKey": "./node_modules/browser-sync/certs/server.key"
        },

3.server.ts 修改function run()

TypeScript 复制代码
function run(): void {
  const port = process.env['PORT'] || 4200;
  
  // https certificates
  const privateKey = fs.readFileSync('./node_modules/browser-sync/certs/server.key');
  const certificate = fs.readFileSync('./node_modules/browser-sync/certs/server.crt');
  // Start up the Node server
// Start up the Node server
let server;
if (process.argv && process.argv.includes('--ssl')) {
    server = https.createServer({ key: privateKey, cert: certificate }, app());
} else {
    server = app();
}
  server.listen(port, () => {
      console.log(`Node Express server listening on https://localhost:${port}`);
  });
}
相关推荐
Lsetea1 分钟前
Nginx加载证书时报SSL_CTX_use_PrivateKey_file失败:私钥配对与权限排查
nginx·https·ssl证书·私钥·证书部署
可乐鸡翅yeah_1 小时前
hls.js 手动自定义 http 请求 loader,修改请求头实战
开发语言·前端·javascript·网络协议·http·ecmascript·m3u8在线
pt10434 小时前
CML网络仿真入门-2:使用CML模拟网络实验环境
运维·网络协议
熊文豪9 小时前
KingbaseES 数据加密全解:从 SSL 到全密态
网络·网络协议·ssl
网络小江9 小时前
上网第三十八课:TCP 三次握手与四次挥手——连接到底是怎么“谈“成的
网络协议
AIgorithmGEEK10 小时前
[Linux]HTTP 应用层协议全解(下篇)
linux·网络·网络协议·http·cookie·无连接·无状态
DP DPharness10 小时前
手机连不上 DSH 时的排错顺序:从 401 到 WebSocket 放行
websocket·网络协议·智能手机
91刘仁德11 小时前
传输层协议深度拆解:端口寻址、UDP 报文与 TCP 可靠性机制全解析
linux·网络·c++·网络协议·tcp/ip·udp·c
傲世仙尊11 小时前
TCP报头全解-序号确认应答与可靠性是一个准数
驱动开发·网络协议·tcp/ip