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 小时前
WebSocket 协议
网络·websocket·网络协议
funnycoffee1233 小时前
lacp报文占多少字节?报文的目的mac
网络·网络协议·macos
lihao lihao4 小时前
Tcp Socket
网络·网络协议·tcp/ip
从零开始的代码生活_4 小时前
Linux select 多路转接详解
linux·运维·服务器·网络·网络协议·tcp/ip·计算机网络
2401_868534784 小时前
网络安全:信息加密、认证(鉴别)、数字签名(CA)、密钥安全分发
网络·网络协议
国强_dev13 小时前
技术探讨:使用 stunnel 加密转发数据库连接时,如何获取客户端真实 IP?
数据库·网络协议·tcp/ip
AlfredZhao20 小时前
Linux 主机防火墙如何同时开启 80 和 443?
http·https·firewall
从零开始的代码生活_20 小时前
NAT、代理服务与内网穿透详解
linux·服务器·网络·c++·http·智能路由器
云栖梦泽在20 小时前
Claude Code / Codex 使用卡顿怎么办?AI 编程 Agent 连接失败与网络排查思路
网络·人工智能·网络协议·chatgpt·性能优化
子不语1801 天前
从0开始学习S7-1200+ET200SP(3)——两台S7-1200通过TCP连接
网络协议·学习·tcp/ip