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}`);
  });
}
相关推荐
caimouse2 小时前
TDI (传输驱动接口 Transport Driver Interface) 详细分析
网络协议
shengnan_wsn5 小时前
【协议】【TCP】
网络·网络协议·tcp/ip
消失的旧时光-19436 小时前
第 3 篇:机器人 TCP 长连接如何稳定运行?心跳、掉线检测与自动重连
网络协议·tcp/ip·机器人
不弃君7 小时前
在 Windows 上用 MinGW 搭建 lwIP 调试环境:方法与踩坑实录
windows·网络协议·tcp/ip·嵌入式·mingw·lwip
NeilYuen10 小时前
实现TCP发送HTTP请求
网络协议·tcp/ip·http
ARoger_miu5712 小时前
opsf笔记
网络·网络协议
caimouse12 小时前
tcpip.sys 网络层 (IP) 详细分析
网络·网络协议·tcp/ip
wuhuhuan13 小时前
Day17:HTTP 接口测试与链式调用 — sendRequest 从入门到实战
网络·网络协议·http
执笔画流年呀14 小时前
网络原理(http)(https)
网络·http·https
m0_5474866614 小时前
《网络协议安全》全套PPT课件(太原理工大学)
网络协议·安全·网络安全