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}`);
  });
}
相关推荐
zt1985q6 小时前
本地部署网页监控工具 Webmonitor 并实现外部访问
运维·服务器·网络·网络协议
缪懿8 小时前
应用层中的UDP协议原理
网络·网络协议·udp·javaee
汤愈韬9 小时前
TK_HCIP-Security_FW的可靠性_双机热备场景_上接路由器下接交换机
网络·网络协议·网络安全
野熊佩骑13 小时前
一文读懂Nginx 之 Ubuntu使用apt方式安装Nginx官方最新版本
linux·运维·服务器·nginx·ubuntu·http
TechWayfarer13 小时前
出海APP本地化实战:基于IP归属地API的网关路由与多语言自动切换方案
网络·python·网络协议·tcp/ip
却道天凉_好个秋14 小时前
云中网络:GRE
网络协议·gre
带娃的IT创业者14 小时前
当隐私守护者成为指纹:深度解析 Mullvad 出口 IP 的“反向识别”陷阱
网络·网络协议·tcp/ip·vpn·指纹识别·隐私保护·mullvad
雪度娃娃14 小时前
Asio——socket的创建和连接
linux·运维·服务器·c++·网络协议
川石课堂软件测试15 小时前
接口测试常见面试题及答案
python·网络协议·mysql·华为·单元测试·prometheus·harmonyos
明豆15 小时前
HTTPS / TLS 1.3 深度解析 — Web 安全传输协议生产实战
前端·安全·https