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}`);
  });
}
相关推荐
奇牙coding1234 小时前
OpenAI Realtime API WebSocket 断连 4008/1006 怎么解决?不是 Key 失效,是实时多模态独有的会话超时规则
python·websocket·网络协议·ai
Helen_cai4 小时前
OpenHarmony http 网络请求封装与全局拦截实战(API Version23 + 适配版)
网络·网络协议·http·华为·harmonyos
刘马想放假4 小时前
生成树协议 STP、RSTP、MSTP 分析:二层环网如何既冗余又不环路
运维·网络协议
gugucoding6 小时前
39. 【C语言】经典 C 项目实战:迷你 HTTP 服务器
c语言·开发语言·http
发光小北6 小时前
SSF-BOX-200 PLC 数据采集网关如何应用?
网络协议
weixin_545019327 小时前
Nginx 配置SSL实现HTTPS访问
nginx·https·ssl
我今晚不熬夜21 小时前
Java语言实现Modbus协议通过用串口读取数据(以RTU为例)
java·网络协议
DLYSB_1 天前
《从零开始搭建机房轻量化“声光告警”系统:基于 HTTP API 与 TTS 的运维实践》
运维·网络协议·http·报警灯
ZhengEnCi1 天前
N3A-一个端口只能给一个程序使用吗?
网络协议
发光的沙子1 天前
FPGA----配置根文件系统ip和mac地址
网络协议·tcp/ip·macos