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}`);
  });
}
相关推荐
Multipath71234 分钟前
多链路聚合,让具身智能高频视觉感知数据 “回得来、来得快、不中断”
网络·网络协议·5g·智能路由器·信息与通信
重生之高冷汉堡包1 小时前
家庭住宅IP是什么?机房住宅与普通住宅有什么区别
运维·服务器·网络·网络协议·tcp/ip·用户运营
j7~2 小时前
【Linux网络加餐】《HTTPS 协议原理》---详解
网络·网络协议·https·加密·ca认证·解密
紧跟先前的步伐4 小时前
Go AI Agent 实战 12|HTTP 状态码、API 错误处理与日志
开发语言·人工智能·http·ai·golang
byte轻骑兵5 小时前
【HIDS】规范精讲[3]:把连接间隔压到极限——SCI 四档调速的底层机制
网络·网络协议·人机交互·hids·蓝牙协议
流浪0015 小时前
计算机网络篇7:传输层——TCP 网络编程常用接口与调用流程
网络协议·tcp/ip·计算机网络·listen·tcp接口
比兔代理6 小时前
静态 IP 的粘性会话原理,以及连接稳定性解析
网络·网络协议
Lsetea6 小时前
curl下载HTTPS正文是乱码:--compressed与Content-Encoding分层排查
linux·http·https·ssl证书·curl
刘胡子大叔7 小时前
curl resolve 和 Host 头的两种免 DNS 验证 HTTPS
网络协议·http·https
j7~7 小时前
【Linux网络加餐】《HTTP 会话保持:Cookie 与 Session 原理及实验验证》---详解
linux·网络·网络协议·http·cookie·session