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}`);
  });
}
相关推荐
Jony_15 小时前
高可用移动网络连接
网络协议
chilix20 小时前
Linux 跨网段路由转发配置
网络协议
gihigo19983 天前
基于TCP协议实现视频采集与通信
网络协议·tcp/ip·音视频
古译汉书3 天前
【IoT死磕系列】Day 7:只传8字节怎么控机械臂?学习工业控制 CANopen 的“对象字典”(附企业级源码)
数据结构·stm32·物联网·http
白太岁3 天前
通信:(5) 电路交换、报文交换与分组交换
运维·服务器·网络·网络协议
EasyGBS3 天前
国标安全升级:GB28181平台EasyGBS支持GB35114协议的应用场景与核心优势
网络协议·安全·gb28181·gb35114
凯酱3 天前
Windows防火墙入站规则IP白名单
windows·网络协议·tcp/ip
稻草猫.3 天前
TCP与UDP:传输层协议深度解析
笔记·后端·网络协议
赤月奇3 天前
https改为http
数据挖掘·https·ssl
科技块儿3 天前
如何用离线库秒筛“数据中心”IP段并自动封号?
网络·网络协议·tcp/ip