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}`);
  });
}
相关推荐
辣椒思密达2 小时前
AI出海产品本地化测试:住宅IP在模拟海外用户环境中的实践价值
网络协议·tcp/ip·安全·php·苹果vision pro
花生了什么事o5 小时前
DNS:把域名翻译成 IP 的层级查询机制
网络·网络协议·tcp/ip
2401_873479406 小时前
金融合规新规下IP查询怎么做?用IP离线库实现数据不出域
网络协议·tcp/ip·金融·ip
微硬创新8 小时前
汽车制造产线协同:耐达讯PROFINETDeviceNet网关在机器人通信中的应用
人工智能·物联网·网络协议·自动化·汽车·制造·信息与通信
米尔的可达鸭8 小时前
深入操作系统 Socket 底层:套接字控制块、FD映射、阻塞IO核心完整实现
arm开发·数据结构·websocket·网络协议·算法·架构·安全架构
Keepingrun10 小时前
http登录和授权
网络·网络协议·http
Lhappy嘻嘻12 小时前
网络初识|基础入门:局域网广域网、IP 端口、TCP/IP 五层模型与封装解封装全过程
java·开发语言·网络·笔记·网络协议·tcp/ip
laoli_coding20 小时前
如何配置HTTPS站点访问的免费SSL域名证书
网络协议·https·node.js·ssl
糖果店的幽灵1 天前
安全测试从入门到精通_网络基础与HTTPS
网络·https·php
Keepingrun1 天前
HTTP基础
网络·网络协议·http