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}`);
  });
}
相关推荐
硬汉嵌入式2 小时前
Microchip开源的自家网络协议栈确实不错,功能完善,并且支持图形化一键配置
网络协议
B2_Proxy4 小时前
IP 来源合规性,正在成为全球业务的隐性门槛
网络·爬虫·网络协议·安全
路由侠内网穿透.6 小时前
本地部署智能家居集成解决方案 ESPHome 并实现外部访问( Linux 版本)
linux·运维·服务器·网络协议·智能家居
吠品6 小时前
什么是 IP SSL 证书?该如何申请
网络协议·tcp/ip·ssl
奋斗羊羊7 小时前
TCP、UDP 和串口通信对比分析
网络协议·tcp/ip·udp
岚天start9 小时前
Python HTTP服务器添加简单用户名密码认证的三种方案
服务器·python·http
不知名。。。。。。。。9 小时前
传输层————TCP/UDP
网络协议·tcp/ip·udp
REDcker10 小时前
RFC1918私有IP地址空间详解
网络协议·tcp/ip·php
ps酷教程10 小时前
HttpPostRequestEncoder源码浅析
http·netty
Flamingˢ11 小时前
FPGA中的存储器模型:从IP核到ROM的深度解析与应用实例
网络协议·tcp/ip·fpga开发