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}`);
  });
}
相关推荐
xyd陈宇阳17 小时前
面向网络协议初学者的入门指南
linux·运维·网络协议
jzlhll12317 小时前
IOT设备局域网发现IP调研
物联网·网络协议·tcp/ip
历程里程碑17 小时前
Linux 49 HTTP请求与响应实战解析 带http模拟实现源码--万字长文解析
java·开发语言·网络·c++·网络协议·http·排序算法
ZVAyIVqt0UFji17 小时前
高可用虚拟IP(HaVip)技术详解:原理、设计与应用
开发语言·网络·网络协议·tcp/ip·perl
M1582276905517 小时前
SG-TCP-Profibus (M) ModbusTCP 转 Profibus DP 网关:工业双协议无缝互联的高效解决方案
网络·网络协议·tcp/ip
王威振的csdn18 小时前
利用 iptables 实现 IP 透明转发:解决 Docker 容器 IP 无法访问的问题
网络协议·tcp/ip·docker
IP搭子来一个18 小时前
代理IP是什么?有什么用?快速了解与使用指南
网络协议·tcp/ip·php
pupudawang19 小时前
使用 Nginx 搭建代理服务器(正向代理 HTTPS 网站)指南
运维·nginx·https
九硕智慧建筑一体化厂家20 小时前
什么是楼宇自控?全面解析楼宇自控与楼宇自控系统的作用
大数据·运维·人工智能·网络协议·制造
Never_Satisfied20 小时前
通过certbot安装SSL证书
网络·网络协议·ssl