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}`);
  });
}
相关推荐
落叶_Jim9 小时前
2026年Nginx配置HTTPS全流程-从零到自动续期实战指南
运维·nginx·https
Arman_10 小时前
02 rusty-cat 实战:MeowClient 配置、任务参数、进度回调与暂停恢复
http·https·rust·tokio·文件分片上传·文件分片下载
汤愈韬12 小时前
hcip-security_防火墙高可靠技术3_防火墙链路高可靠技术
网络·网络协议·网络安全
liulilittle14 小时前
TCP UCP v1.0:当 BBRv1 遇上卡尔曼滤波
网络·网络协议·tcp/ip
wangjialelele15 小时前
HTTP Cookie 和 Session
http·cookie·session
小娄~~15 小时前
TCP/IP协议和TFTP协议
网络·网络协议·tcp/ip
xiaoxue..15 小时前
HTTPS:更安全的HTTP,从加密原理、数字证书到TLS 握手全解析
网络协议·面试·https
liulilittle15 小时前
TCP UCP v1.0 拥塞控制算法(Linux Kernel CC-A)
linux·网络·网络协议·tcp/ip·c·通信·拥塞控制
仍然.16 小时前
传输层协议UDP
网络·网络协议·udp
艾莉丝努力练剑16 小时前
【Linux网络】Linux 网络编程:HTTP(一)协议初识
linux·运维·服务器·网络·tcp/ip·计算机网络·http