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}`);
  });
}
相关推荐
发光小北25 分钟前
四路can转WIFI在现场应用中有什么问题?
网络协议
zxanz15 小时前
网站为什么需要 SSL 证书来实现 https?
https
长按助力退休7 小时前
HTTP缓存从强缓存到协商缓存,前端性能优化第一步
http
Lsetea10 小时前
curl报58 unable to set private key file:客户端证书与私钥加载排查
运维·https·ssl证书·openssl·curl
Lsetea11 小时前
OpenSSL报certificate is not yet valid:error 9与notBefore时间排查
linux·运维·https·ssl证书·openssl
2501_9159090611 小时前
iOS应用从开发到上架App Store的完整发布流程与步骤指南
android·ios·小程序·https·uni-app·webview
刘马想放假11 小时前
网络链路备份与高可用技术详解:从 Dual-WAN、LACP 到 SD-WAN 与 MPTCP
网络协议
Zelman12 小时前
第07章-数据中心网络
后端·网络协议
Smoothcloud润云13 小时前
GPU服务器租用实例DNS与HTTPS下载排障实战
大数据·运维·服务器·人工智能·https·gpu算力
网络小江15 小时前
上网第四十八课:抓包实战入门——Wireshark 读懂第一个包
网络协议