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}`);
  });
}
相关推荐
xlq2232244 分钟前
62.udp tcp原理
网络协议·tcp/ip·udp
Seven971 小时前
别只会背 200 和 404:HTTP 核心知识完整梳理
tcp/ip·http
Aaswk1 小时前
计算机网络概述
网络·网络协议·tcp/ip·计算机网络·http·dubbo
梦奇不是胖猫1 小时前
[ 计算机网络 | 第四章 ] 网络层 02 网际协议IP
运维·服务器·网络·网络协议·tcp/ip·计算机网络
艾莉丝努力练剑1 小时前
【Linux网络】Linux 网络编程:传输层TCP(四)
linux·运维·服务器·网络·tcp/ip·http
深邃-2 小时前
【Web安全】-10-网站关键信息收集:目录扫描的概念,工具目录扫描(内含御剑,FindSomething安装链接),网站服务器收集,操作系统判断
运维·服务器·安全·web安全·http·网络安全
XLYcmy13 小时前
全链路验证测试系统:一个针对智能代理(Agent)系统全链路能力的自动化验证脚本
分布式·python·http·网络安全·ai·llm·agent
带刺的坐椅16 小时前
Solon Server 启动模式深度解析:从 0.3MB 内核到 10+ Server 插件
java·http·solon·jetty·undertow
掉鱼的猫16 小时前
Solon Server 启动模式深度解析:从 0.3MB 内核到 10+ Server 插件
java·http
林熙蕾LXL18 小时前
socket编程-TCP开发常用函数
网络协议·tcp/ip·php