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}`);
  });
}
相关推荐
Avan_菜菜6 小时前
FRP 内网穿透完整实战:从 HTTP 映射到 HTTPS 自签代理
运维·nginx·https
用户2530171996277 小时前
第6篇:从技术到产品 — Ghost Proxifier 的设计哲学
网络协议
用户2530171996277 小时前
第3篇:注入的艺术 — Ghost Proxifier 核心架构拆解
网络协议
王二端茶倒水2 天前
商业 WiFi 不是免费上网,而是门店数字化的入口
网络协议
霜落长河5 天前
抛弃TCP改用UDP,HTTP3怎么了?
http
程序员mine6 天前
HTTPS-TLS加密与证书完全指南(中)
网络协议·https·ssl
之歆6 天前
现代 HTTP 客户端深度解析:Fetch 与 Axios
chrome·网络协议·http
酉鬼女又兒7 天前
零基础入门计算机网络运输层:端到端通信核心作用、端口号分类规则、复用分用工作机制及UDP与TCP协议全方位对比详解
网络·网络协议·tcp/ip·计算机网络·考研·udp·php
dog2507 天前
不要再继续优化 TCP
网络协议·tcp/ip·php
程序员mine7 天前
HTTPS-TLS加密与证书完全指南(上)
网络协议·https