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}`);
  });
}
相关推荐
DLYSB_1 小时前
《从零开始搭建机房轻量化“声光告警”系统:基于 HTTP API 与 TTS 的运维实践》
运维·网络协议·http·报警灯
ZhengEnCi1 小时前
N3A-一个端口只能给一个程序使用吗?
网络协议
发光的沙子1 小时前
FPGA----配置根文件系统ip和mac地址
网络协议·tcp/ip·macos
2501_915909062 小时前
IPA 深度混淆是什么意思?从混淆强度到实际效果的解读
android·ios·小程序·https·uni-app·iphone·webview
一棵树73514 小时前
跨域资源共享cors
http·cors
华清远见成都中心16 小时前
物联网通信协议对比:MQTT、CoAP、HTTP到底该怎么选
物联网·网络协议·http
kk的vmware虚拟机安装ubuntu17 小时前
鱼皮 yu-rpc:从 0 到 1 手写 RPC 框架的实践教程
网络·网络协议·其他·rpc
耍酷的魔镜18 小时前
谈谈如何使用Netty开发实现高性能的RPC服务器
服务器·网络协议·rpc
墨神谕18 小时前
JSON-RPC 2.0
网络协议·rpc·json
apihz1 天前
随机驾考题目(C 照科一 / 科四 2000+ 题)免费API调用教程
android·java·c语言·开发语言·网络协议·tcp/ip