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}`);
  });
}
相关推荐
HMS工业网络4 小时前
如何解决使用TwinCAT时EtherCAT网络出现“Sync Manager Watchdog”报错
网络·网络协议·网络安全
审判长烧鸡9 小时前
标准 HTTP API 签名鉴权 Header 完整规范
http·web
w1wi9 小时前
安卓抓包完全指南(一):从入门到 SSL Pinning 绕过
android·网络协议·ssl
刘马想放假12 小时前
OpenVPN 深度解析:从协议原理到生产实践
运维·网络协议
00后程序员张13 小时前
HTTPS单向认证、双向认证、抓包原理与反抓包策略详解
网络协议·http·ios·小程序·https·uni-app·iphone
June bug14 小时前
Failed to fetch+HTTP 422=Agent ID 不匹配
网络·网络协议·http
minji...16 小时前
Linux 网络基础之传输层协议TCP(九)从内核源码的角度打通系统与网络之间的关系,套接字多态的体现
linux·运维·服务器·网络·网络协议·tcp/ip·http
灰子学技术17 小时前
Envoy IP 标签(IP Tagging)功能实现分析
网络·网络协议·tcp/ip
想唱rap17 小时前
IO多路转接之epoll
linux·运维·服务器·数据库·网络协议·算法·http
初願致夕霞17 小时前
Linux网络编程_数据链路层MAC帧协议与ARP协议
linux·网络·网络协议·macos