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}`);
  });
}
相关推荐
初中就开始混世的大魔王1 小时前
3.1 DDS 层-Core
开发语言·c++·网络协议·tcp/ip·信息与通信
亿牛云爬虫专家1 小时前
爬虫踩坑实录:OkHttp 接入爬虫代理报 Too many tunnel connections attempted 深度解析
爬虫·okhttp·https·爬虫代理·connect·隧道代理·ip 切换
有代理ip3 小时前
聚焦性价比:便宜动态IP在网络优化中的应用技巧
网络·网络协议·tcp/ip
m0_651593913 小时前
从羊肠小道到智能高速:HTTP1到HTTP3的演进之路
http
wanhengidc3 小时前
云手机 流畅稳定 操作简单
服务器·网络·网络协议·安全·智能手机
zl_dfq3 小时前
计算机网络 之 【https协议】(数字摘要、密钥、数字证书)
网络协议·计算机网络·https
北京耐用通信3 小时前
工业协议转换新选择:耐达讯自动化CC-Link I转EtherCAT网关深度解析
人工智能·科技·物联网·网络协议·自动化·信息与通信
弹简特5 小时前
【JavaSE-网络部分05】TCP 可靠性 + 高性能的三大核心机制:滑动窗口・流量控制・拥塞控制
网络·网络协议·tcp/ip
Highcharts.js5 小时前
数据更新方案对比|HTTP轮询 vs WebSocket,如何为你的图表选择最佳方案
websocket·网络协议·http·数据更新·highcharts·http轮询·图表数据更新
李庆政3705 小时前
modbus协议四 rtu Over tcp & mbslave & CRC校验码计算方法
网络协议·tcp/ip·modbus·rtu over tcp