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}`);
  });
}
相关推荐
Bowen_J1 小时前
Flutter和Dart 网络协议实现
网络协议·flutter·dart
大今野9 小时前
第 17 章 IP 编址与子网划分
网络·网络协议·tcp/ip·专转本
mont evergreen17 小时前
青云宗秘录:libp2p 双节点聊天阵法源码卷
服务器·网络协议·p2p
FlightYe1 天前
音视频修炼之容器与协议(七):HTTP-MP4 / HTTP-FLV
linux·网络·网络协议·http·ffmpeg·音视频
用户84913717547161 天前
抄来的 SNMP4J 代码能跑,却把"没回执"记成了"值为 0"——一次 GET 到底该怎么采对?
网络协议
知识汲取者1 天前
HTTP、SSE、WebSocket:三个老技术的区别、场景与选型
websocket·http·ai
ShineWinsu1 天前
对于Qt:TCP的解析
linux·c++·qt·网络协议·面试·tcp·客户端
郝学胜-神的一滴1 天前
Effective Python 条款45:巧用属性注解平滑升级类属性
运维·开发语言·数据库·python·网络协议·numpy
SEO_juper1 天前
HTTPS 混合内容检查工具:页面全站 https 了,但还有 http 资源在拖后腿
开发语言·网络协议·http·https·node.js·json·bash
进击的荆棘2 天前
Linux网络——应用层协议HTTP
linux·运维·服务器·网络·http