I'm trying to serve a ReactJS app together with an API built with Spring Boot. I've run the script create-react-app
on /public/ - as shown on the structure below - however, all relative paths from ReactJS seems to be broken when I try to access it from http://localhost:8080/public/index.html
What else do I need to do in order to correctly load the resources from ReactJS?
The basic idea of what Spring Boot and Create React App do. Create React App helps you start a React project very quickly. It gives you all the basic things you need to get up and running asap. Spring boot helps you start and maintain a spring application quickly and easily.
To run your React Native app, you'll need to start your Spring Boot app first. Navigate to the jhipster-api directory and run ./gradlew . In another terminal window, navigate to react-native-app/ios and run pod install . Then navigate up a directory and run react-native run-ios .
Go to File>New>Project>React and select React Project to create a new React template project. You can create JavaScript or TypeScript applications with this wizard.
I suggest you create two projects:
create-react-app
.In dev mode, you have to run the React development server with node: 'npm start'.
You should define a proxy to your Spring Boot app: "proxy": "http://localhost:8080",
to add to your package.json
. Documentation of this mechanism is here.
And you can execute your backend as usual with Gradle: ./gradlew bootRun
.
In production deployment, you can generate a build of your React app with npm run build
. The static files produced by create-react-app
can be placed in a static directory in your Spring Boot application, for instance in src/main/resources/static/
(docs about static content with Spring Boot)
I hope this helps!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With