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}`);
  });
}
相关推荐
可爱系程序猿10 小时前
Windows 打印链路诊断:从设备枚举、TCP/IP 端口到 Spooler 服务恢复
网络·网络协议·tcp/ip
深念Y12 小时前
P2P组网选型与折腾记录
网络·网络协议·p2p·局域网·远程·组网
会编程的土豆12 小时前
MySQL 入门:库、表、行、主键是什么
linux·数据库·网络协议·http
阿kun要赚马内12 小时前
DNS了解
网络协议
paopaokaka_luck13 小时前
基于Springboot3+Vue3的高校选课系统(AI选课助手、协同过滤算法、分享到微博、扣扣、Echarts图形化分析)
网络·spring boot·网络协议·echarts
BullSmall15 小时前
AFL++ HTTP Mode(网络 / HTTP 服务模糊测试)完整安装教程
网络·网络协议·http
caimouse17 小时前
TCP/IP 协议驱动 (tcpip.sys) 分析
网络协议·tcp/ip·reactos
便利店102417 小时前
快递选「挂号」还是「平邮」?传输层一次讲清
网络·网络协议·tcp/ip·传输层
夜雪一千18 小时前
UDP 协议简介
网络·网络协议·udp
想你依然心痛19 小时前
TCP/IP协议栈深度解析:从底层原理到高性能优化实践
网络协议·tcp/ip·性能优化