简体   繁体   中英

Running react-scripts app with input from another server

I'm having some difficulty passing information between different servers and them showing what I want. I have one server where I get my data from (a JSON file), and another server which runs a react application. I want to pass information to this react application (preferably the json content), and then serve the react application, maybe from an express app's post method?

Is there a way to pass information in this way? Right now I'm trying to fetch the data from one server, the webpacked index.html from another, and mashing them together with some string parsing (using window.data global values to get the json file in there). This doesn't include icons, and I get errors about disconnecting from the development server when I run.

To reiterate, I want to serve a react application with input coming from a completely different server. If you have any tips for how to accomplish this, it would be greatly appreciated.

How about something like this (pseudo code):

YourReactComponent {

  componentDidUpdate() {
        fetch(other_server_URL, ...)
        .then((res) => {
            if (res.ok) {
                return res.json();
            }
        })
        .then((jsonString) => { 
            this.parseYourJson(jsonString);
        });
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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