【问题标题】:Can I provide different baseref for Angular Universal SSR and clientside rendering?我可以为 Angular Universal SSR 和客户端渲染提供不同的基本 href 吗?
【发布时间】:2019-10-03 14:23:19
【问题描述】:

我有一个有角度的通用应用程序。使用以下命令直接从节点 (localhost:4000) 运行时,一切正常: npm 运行构建:ssr npm 运行服务:ssr

对于生产,我需要在子路径(服务器名/应用程序名)而不是根目录中提供应用程序。网络服务器是 apache,我使用 proxypass 如下: ProxyPass "/appname/" "http://localhost:4000/"

现在解决问题: 对于 SSR,baseref 是“/”,但对于客户端渲染,baseref 是“/appname”。这意味着,在 root 上使用 node/express 的 SSR 或在 servername/appname 上运行应用程序的客户端都无法找到 index.html(main.js 等)中链接的文件

是否可以为 SSR 和 CSR 提供​​不同的 baseref?

我能想到的一个技巧是将 SSR 应用程序托管在“localhost:4000/appname”……但我不知道如何在我的 server.ts 中配置它……

非常感谢任何帮助!

【问题讨论】:

    标签: node.js angular apache universal server-side-rendering


    【解决方案1】:

    至少我现在已经让节点在相同的 href 下运行 SSR 应用程序

    const allowed = [
      '.js',
      '.css',
      '.png',
      '.jpg',
      '.svg',
      '.woff',
      '.ttf'
    ];
    const disallowed = [
      '.map'
    ]
    
    app.get('/appname/*', (req, res) => {
      if (allowed.filter(ext => req.url.indexOf(ext) > 0).length > 0 && disallowed.filter(ext => req.url.indexOf(ext) > 0).length == 0) {
         res.sendFile(resolve(DIST_FOLDER + req.url.replace("appname/", "")));
      } else {
        res.render('index', {req})
         //res.sendFile(path.join(__dirname, 'client/dist/client/index.html'));
      }
    });
    

    【讨论】:

      猜你喜欢
      • 2020-12-26
      • 2021-11-01
      • 2020-12-16
      • 2020-11-06
      • 1970-01-01
      • 2020-03-05
      • 2019-10-08
      • 2016-11-10
      • 2021-06-07
      相关资源
      最近更新 更多