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}`);
  });
}
相关推荐
牛马工作号14 小时前
Wi‑Fi 完全指南:从 802.11 协议到 Wi‑Fi 7、AC+AP 与 Mesh 工程组网
网络·网络协议·智能路由器
Geek-Chow15 小时前
ALB SSL policy conflict (AWS Load Balancer Controller)
网络协议·ssl·aws
爱刷碗的苏泓舒15 小时前
FTP、FTPS 与 WinSCP:原理、连接机制及 GNSS 工程应用
网络协议·ftp·winscp·数据下载·ftps
雲帝15 小时前
Windows虚拟机UDP大包分片排障
windows·网络协议·udp
ControlRookie15 小时前
第04篇_把 HTTP 放进 PLC:扫描周期、缓冲区、状态机和能力边界
http·codesys·plc通信
八代臻16 小时前
蒲公英免费异地组网
网络协议
記億揺晃着的那天17 小时前
HTTPS 页面内网直连 NAS:解决 Mixed Content 与公网带宽瓶颈
网络协议·http·https·nas
難釋懷18 小时前
Nginx代理https请求
redis·nginx·https
想学好C++的oMen19 小时前
socket编程TCP
linux·网络·网络协议·tcp/ip
GitLqr1 天前
别再盲目复制了:彻底搞懂 CORS 的本质与那些“神坑”
安全·http·面试