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}`);
  });
}
相关推荐
IpdataCloud2 小时前
批量查IP的API接口怎么选?免费API配额瓶颈与离线库本地批量方案实测
网络·网络协议·tcp/ip
GIoT80105 小时前
整段 C 段 IP 不能只看 Ping:一套实用的批量检测与分析思路
http
伤心的梧桐叶7 小时前
商品大图断点续传后打不开,先看是不是把完整响应又接了一遍
http·https
网络小江8 小时前
组网第33课:IP 地址与子网——CIDR、掩码、VLSM、网段规划与可用地址速算
网络协议·tcp/ip·子网掩码·vlsm·网络规划
山雀~9 小时前
WebSocket 断连之后:一次手机采集偶现卡死的排查与修复
网络·websocket·网络协议
码少女9 小时前
Linux——网络层-IP协议以及路由选择
linux·网络·网络协议·tcp/ip
dsadas10 小时前
ospf宣告网段的理解
网络协议
爱研究的小梁12 小时前
从无人车配送走向集群联动作业,通信如何扛住协同压力?
网络·网络协议·机器人·信息与通信
汤愈韬13 小时前
OSPF的虚链路
网络·网络协议
火22513 小时前
# C++ 微服务即时通讯系统(三):网关设计——HTTP 请求、Session 鉴权与 WebSocket 通知上一篇
c++·http·微服务