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 小时前
网络原理04(http协议详细解析3)(2000详细解析HTTPS的工作原理)
网络·网络协议·http
额额额对了4 小时前
Linux 进程间通信(IPC)核心机制:消息队列、共享内存与信号量详解
linux·网络·网络协议
IPdodo_4 小时前
2026年爬虫代理 IP 选择指南:从可用率、延迟到成本验收
网络协议·tcp/ip·scrapy·http·https·beautifulsoup·httpx
程序员夏洛5 小时前
HTTP 请求包含哪些内容,请求头和请求体有哪些类型?
网络·网络协议·http
瓦格哈儿6 小时前
删掉旧 SSL 证书会影响线上业务吗?风险点梳理
网络协议·https·ssl
美酒没故事°7 小时前
https和tls有什么区别?
网络协议·http·https
Lsetea9 小时前
Cloudflare报526 Invalid SSL certificate:源站证书与Nginx回源TLS排查
nginx·https·ssl证书·cloudflare·tls
Lsetea9 小时前
SSL证书快过期怎么自动检查:用OpenSSL checkend做7天预警与线上证书验收
https·ssl证书·openssl·systemd·证书监控
春风解人意10 小时前
从零开始学习嵌入式P33----网络基础之HTTP
网络·学习·http
2401_8628808210 小时前
Linux应用层开发 --- HTTP
linux·运维·http