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}`);
  });
}
相关推荐
Ether IC Verifier33 分钟前
TCP三次握手与四次挥手详解
网络·网络协议·tcp/ip·计算机网络
pengyi8710158 小时前
独享IP池自动化维护方案,智能检测自动延长使用寿命
网络协议·tcp/ip·自动化
德思特11 小时前
通过 Wireshark 抓取串口命令
网络协议·测试工具·wireshark
KnowSafe13 小时前
2026年SSL证书市场便宜且安全的SSL证书调研
网络协议·安全·ssl
dangdanding16 小时前
防火墙 IP 分片测试套件-fragroute
linux·网络·网络协议·tcp/ip
TechWayfarer16 小时前
AI大模型时代:IP数据云如何适配智能体场景需求
开发语言·人工智能·python·网络协议·tcp/ip·langchain
冰冰的米咖18 小时前
交换与路由技术整理与总结(持续更新版)
网络·网络协议·智能路由器
Ether IC Verifier18 小时前
TCP/IP协议握手原理详解——结合以太网连接过程
服务器·网络·数据库·网络协议·tcp/ip
山栀shanzhi19 小时前
TCP 和 UDP 区别
网络协议·tcp/ip·udp
HMS工业网络20 小时前
使用电脑快速测试PROFIBUS 设备通讯
网络·网络协议·profibus·主站·设备通讯