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}`);
  });
}
相关推荐
神仙别闹4 小时前
基于C++设计一个 P2P 聊天软件
网络·网络协议·p2p
IpdataCloud5 小时前
评估交易IP是否来自制裁国家?IP地址查询+政治敏感标签库实操指
网络·网络协议·tcp/ip·ip
映翰通朱工5 小时前
从0到1:EC942边缘计算机用Python实现Modbus TCP采集+MQTT上云全记录(附踩坑实录)
网络·python·网络协议·tcp/ip·二次开发·映翰通
Shell运维手记21 小时前
ARP 协议超详细讲解(适合网工考试 / 运维理解)
运维·网络·网络协议·智能路由器
ShineWinsu1 天前
对于Linux:HTTP中cookie、session的解析
linux·网络·c++·网络协议·http·cookie·session
huainingning1 天前
华三瘦AP切换为胖AP并配置无线功能
运维·网络·网络协议·tcp/ip
减瓦1 天前
告别Postman——用VSCode优雅地发起Http请求
vscode·http·postman
跨境技工小黎1 天前
4G/5G 移动代理实战:什么时候必须用移动 IP?
网络协议·tcp/ip·5g
wechatbot8881 天前
解决企业微信官方 API 短板:iPad 协议全功能对接方案
java·汇编·windows·http·微信·企业微信
米尔的可达鸭1 天前
UDP 通信深度实验:从 Windows FastPath 到 ICMP 端口不可达的完整排查
windows·websocket·网络协议·rust·udp·wireshark·tcpdump