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}`);
  });
}
相关推荐
Wang's Blog4 小时前
Java框架快速入门: Spring Security+OAuth2之HTTP请求结构与认证基础
java·spring·http
Zenova EdgeOS5 小时前
C++ 工业边缘 libcurl HTTP 客户端实战
开发语言·c++·网络协议·边缘计算
时空节拍AI数字人6 小时前
AI 数字人为什么需要“3D”?2D 不够用吗
人工智能·网络协议·tcp/ip·3d·信息可视化
小白羊丨7 小时前
HTTP/2 如何缓解 HTTP/1.1 阻塞;长连接对 Nginx 有什么影响?
网络协议·nginx·http
我的小卷呀10 小时前
Linux ip 命令底层逻辑与实战指南
linux·运维·c语言·网络协议·tcp/ip·网络安全
Soonyang Zhang12 小时前
使用wintun构建tcp中转服务
网络·网络协议·tcp/ip
木辰風13 小时前
启动了不安全的HTTP方法(漏洞、springmvc)
网络·网络协议·http
ITxiaobing202313 小时前
技术选型参考:从IPinfo出发,聊聊IP情报服务的替代方案与选型逻辑
网络·网络协议·tcp/ip
z_mazin14 小时前
逆向一种私有二进制序列化格式:从零到字节级解析器
网络·python·网络协议·算法·rpc
Jeremy_WW14 小时前
QSFP/QSFP-DD/OSFP 通用管理接口规范(CMIS)解读:11 Page 13h IV
网络·网络协议·信息与通信·光模块·cmis