简体   繁体   English

如何在React中创建SPA以通过SSI包含

[英]How to create a SPA in React to be included through a SSI

We've been tasked with creating a micro-service front end for another group. 我们的任务是为另一个小组创建微服务前端。 We're wanting to create this in React, and the group we're building it for are wanting to include this through a SSI to be a part of their larger page. 我们想在React中创建它,而我们为其构建的小组则希望通过SSI将其包含在他们更大的页面中。 I've setup my own Nginx server and created a test page to include my basic react app and this worked to include the contents of the page. 我已经设置了自己的Nginx服务器,并创建了一个测试页面以包含我的基本React应用,并且该工作包含了页面的内容。 However, the content of the react page is pointing to relative URL's for things like bundle.js, 0.chunk.js; 但是,react页面的内容指向诸如bundle.js,0.chunk.js之类的相对URL。 main.chunk.js; main.chunk.js; I have setup rules for this in Nginx to also bring those for the origin, but that's less than ideal and I'm still getting 404's on other resources react is trying to pull in. 我在Nginx中为此设置了规则,也将这些规则引入了原点,但这并不理想,我仍然在其他资源上得到404的响应,试图引入。

What's the best way to solve this? 解决此问题的最佳方法是什么? Is there a way for React to bundle all it's resources into a single file? React是否有办法将所有资源捆绑到一个文件中? Or is what we're trying to do just not feasible? 还是我们试图做的事不可行?

Here is the segment of my nginx file I'm using to include my react app: 这是我用来包括我的react应用程序的nginx文件的片段:

location /test.html {
    ssi on;
    proxy_set_header Accept-Encoding ""; 
    proxy_pass http://local.react.com:3000/;        
}

I added more of these to bring in the JS from the react app that react inserts into the page. 我添加了更多这些内容以从react应用程序中引入JS,该应用程序将react插入页面。

The page I'm including it on just has the include: 我要包含的页面仅包含:

<!--#include virtual="test.html" -->

You probably need to change some configuration options. 您可能需要更改一些配置选项。 Check create-react-app documentation about PUBLIC_URL setting or webpack documentation about output.publicPath setting. 检查创建反应的应用程序内的文件PUBLIC_URL设置或文档的WebPack约output.publicPath设置。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM