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}`);
  });
}
相关推荐
yuegu77726 分钟前
HarmonyOS应用<节气通>开发第25篇:HTTP请求封装
网络协议·http·harmonyos
IT大白鼠1 小时前
BGP多归属技术原理与应用实践
网络·网络协议·华为
忧云2 小时前
HTTP抓包工具:安装配置与使用教程
网络协议·网络抓包工具·http抓包
00后程序员张2 小时前
Jenkins 自动上传 IPA 到 App Store 把发布步骤融入 CI/CD
android·ios·小程序·https·uni-app·iphone·webview
serve the people2 小时前
Elasticsearch(5) i want to monitor the es health from a http api
大数据·http·elasticsearch
Mr -老鬼2 小时前
EasyClick 入门指南:HTTP 网络请求与 API 对接实战
网络·网络协议·http·自动化·#easyclick
Shacoray3 小时前
K8s 中 Ingress 的 HTTPS 证书 如何生成?
容器·https·kubernetes
上海云盾第一敬业销售3 小时前
WAF架构解析与实战经验分享
网络协议·web安全·架构
行走__Wz3 小时前
【网工入门-01】模拟器工具eNSP
网络·网络协议
用户337922545683 小时前
A2A 协议规范深度剖析:三层架构、数据模型、操作语义与协议绑定
网络协议