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 小时前
【jsonRpc项目】常用的零碎功能接口实现
网络协议·http
googleccsdn3 小时前
ENSP Pro Lab笔记:配置BGP EVPN VXLAN双栈(2)
网络·笔记·网络协议
陌路204 小时前
RPC分布式通信(3)--RPC基础框架接口
分布式·网络协议·rpc
Dreamboat_LX5 小时前
websocket-sockjs-stomp
网络·websocket·网络协议
ps酷教程6 小时前
HttpPostRequestEncoder使用示例
http·netty
txinyu的博客6 小时前
TCP的可靠性问题
网络·网络协议·tcp/ip
陌路207 小时前
RPC分布式通信(1)--分布式通信讲解
分布式·网络协议·rpc
php_kevlin8 小时前
websocket实现站内信
android·websocket·网络协议
2401_865854888 小时前
ssl证书使用中可能会遇到的问题
网络·网络协议·ssl
捷米研发三部9 小时前
CANopen 转 Modbus TCP:智能机床控制器与上位机监控系统的无缝对接方案
网络·网络协议