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}`);
  });
}
相关推荐
青瓦梦滋3 小时前
传输层UDP/TCP协议
linux·网络·c++·网络协议·tcp/ip·udp
xiaoxiangsiyan7 小时前
HCIA 网络技术基础核心模块详解
运维·网络·网络协议·tcp/ip·运维开发·网络基础
2501_916007479 小时前
Bundle ID 注册与管理 App ID 创建指南 命名规则 权限开关与删除注意事项
android·ios·小程序·https·uni-app·iphone·webview
2401_8685347810 小时前
存储与虚拟化
linux·网络协议
微硬创新12 小时前
如何让4-20mA信号跑上PROFINET高速路?耐达讯自动化NY-PN-A160C给出答案
人工智能·物联网·网络协议·自动化·信息与通信
kels889913 小时前
实战排坑:黄金实时API开发,XAUUSD Tick报文异常处理实践
开发语言·python·websocket·网络协议·信息可视化
Bobolink_13 小时前
IP更换频率:账号运营里多久换一次IP算正常
大数据·网络协议·tcp/ip
treesforest14 小时前
你的IP干净吗?
网络·网络协议·tcp/ip·跨境电商·ip归属地查询·跨境
sbjdhjd14 小时前
大三网安秋招核心学习前言(AI 安全 + Web 漏洞 + 内网渗透全考点)
人工智能·网络协议·学习·安全·网络安全·开源·php
llllll15214 小时前
深入浅出计算机网络:从 TCP 可靠传输到 DNS 解析核心原理
网络协议·tcp/ip·计算机网络