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}`);
  });
}
相关推荐
一个心烑20 分钟前
配置项目git的 SSL 证书
git·网络协议·ssl
发光小北8 小时前
西门子 PLC 串口转网口模块现场应用有哪些问题?
网络协议
楚Y6同学12 小时前
QT上位机开发-UDP通信-模拟下位机数据联调的方法
网络协议·udp·联调方法
captain37618 小时前
网络原理(3)-TCP核心机制连接管理▲▲▲
java·服务器·网络·ide·网络协议·tcp/ip·java-ee
易岳群18 小时前
搞清 Socket、TCP、MQTT 的通信关系:从底层协议到物联网实战
网络协议·tcp/ip·socket·通信协议关系
宵时待雨18 小时前
linux笔记归纳19:网络层协议IP
linux·网络·笔记·网络协议·tcp/ip
只睡四小时19 小时前
内网穿透+WebSocket:Node 零依赖远程桌面实战
网络·websocket·网络协议
Jeremy_WW19 小时前
802.3协议解读 05:116章节 200 Gb/s 和 400 Gb/s 网络介绍 V
网络·网络协议·信息与通信·光模块·802.3协议
梦想平凡20 小时前
百游棋牌源代码开发搭建教程(七):WebSocket房间同步与断线恢复
网络·websocket·网络协议
Lsetea20 小时前
Java 请求 HTTPS 报 PKIX path building failed:从证书链到 truststore 的完整排查
java·https·ssl证书·keytool·truststore