Reactjs 将react应用程序中的html代码插入express

Reactjs 将react应用程序中的html代码插入express,reactjs,express,Reactjs,Express,我有一个包含以下域(通配符子域)的express应用程序 我在cdn.example.com上也有一个react应用程序 我需要将react应用程序加载到subdomain2.example.com 基本上,我在express应用程序中有一些逻辑检查subdomain是否等于subdomain1,然后它应该加载react应用程序,否则只需在页面中打印一些内容 我正在考虑这样做,从cdn中读取index.html并将其返回到express应用程序中 router.get('/', (req, re

我有一个包含以下域(通配符子域)的express应用程序

我在cdn.example.com上也有一个react应用程序

我需要将react应用程序加载到subdomain2.example.com

基本上,我在express应用程序中有一些逻辑检查subdomain是否等于subdomain1,然后它应该加载react应用程序,否则只需在页面中打印一些内容

我正在考虑这样做,从cdn中读取index.html并将其返回到express应用程序中

router.get('/', (req, res) => {
    if (req.subdomains[0] === 'subdomain1') {
        request('http://cdn.example.com/index.html', function (error, response, body) {
            return res.status(200).send(body)
        });
    } else {
        return res.status(200).send('hello world')
    }
});
这是可行的,但我认为这不是正确的方法。我只在react应用程序中找到了直接指向index.html的域的示例

我最大的问题是react应用程序在每次构建时都会更改哈希值。这就是我抓取整个html React index.html文件的原因。

您可以重定向:

router.get('/', (req, res) => {
    if (req.subdomains[0] === 'subdomain1') {
        res.redirect('http://cdn.example.com/index.html')
    } else {
        return res.status(200).send('hello world')
    }
});
router.get('/', (req, res) => {
    if (req.subdomains[0] === 'subdomain1') {
        res.redirect('http://cdn.example.com/index.html')
    } else {
        return res.status(200).send('hello world')
    }
});