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}`);
  });
}
相关推荐
80s77710 小时前
住宅代理解析:动态住宅IP与静态住宅IP如何选型?
网络·网络协议·tcp/ip
略略略咯咯14 小时前
网络协议-study
网络·网络协议
DLYSB_15 小时前
从监控告警到现场处置:用 HTTP API、Modbus TCP 构建声光语音告警系统
网络协议·tcp/ip·http·报警灯
爱学习的程序媛15 小时前
通信协议完整梳理
网络·网络协议·信息与通信·通信协议
佳児素花痴╮16 小时前
服务器模型、网络调试工具、网络协议头分析
服务器·网络·网络协议
阿pin16 小时前
TCP VS UDP
网络协议·tcp/ip·udp
treesforest18 小时前
信贷反欺诈实战:通过IP属地一致性核验识别虚假贷款申请
网络协议·tcp/ip·php
佳児素花痴╮20 小时前
UDP编程与网络通信
网络·网络协议·udp
SendTomo21 小时前
SendTomo稳定传输三大核心策略
javascript·网络协议·webrtc·html5·p2p
CANWeb冗余现场总线1 天前
2毫秒扫描周期以太网Modbus TCP UDP高速通信:西门子SMART PLC+CANWeb现场总线远程扩展IO模块
网络协议·tcp/ip·udp