【问题标题】:How can I serve a domain specific manifest.json for a heroku app with mirrored domains?如何为具有镜像域的 heroku 应用程序提供特定于域的 manifest.json?
【发布时间】:2019-02-19 21:16:12
【问题描述】:

我有一个我正在开发的 create-react-app 应用程序,该应用程序镜像到多个域。每个域都有自己的品牌,现在我们支持 PWA 应用程序安装,我们希望根据用户访问的域提供不同的图标和应用程序名称。不幸的是,由于这些域都指向同一个 Heroku 实例,我一直无法想出一种方法来设置清单文件来执行此操作。是否有一些heroku设置,我可以为来自域A的访问者提供清单A,为来自域B的访问者提供清单B?我们应该托管两个应用程序吗?

【问题讨论】:

    标签: reactjs heroku create-react-app


    【解决方案1】:

    这可能不是最好的解决方案,但我最终切换了构建包并编写了我们自己的快速服务器来为我们的应用程序提供服务。我为 /index 设置了路线,用 pwa 兼容性所需的正确清单和元标记替换特定的 dom 元素。这是有问题的路线:

    app.get('/index.html', async (req, res) => {
      const indexBuffer = await readFileAsync(path.join(__dirname, 'build', 'index.html'));
    
      let index = indexBuffer.toString('utf8');
      let manifestConfig = defaultConfig;
    
      if (req.hostname === 'app.otherHostName.com') {
        manifestConfig = otherHostNameConfig;
      }
    
      index = index.replace('<link rel="manifest">', manifestConfig);
    
      return res.send(index);
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2015-11-07
      • 2011-06-05
      • 2013-10-21
      • 1970-01-01
      • 2016-10-16
      • 1970-01-01
      相关资源
      最近更新 更多