How can I use create-react-app with Spring Boot?

前端 未结 1 692
死守一世寂寞
死守一世寂寞 2021-01-05 04:56

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 be

1条回答
  •  不知归路
    2021-01-05 05:18

    I suggest you create two projects:

    • one for your Spring Boot backend;
    • one for your React frontend, created with 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!

    0 讨论(0)
提交回复
热议问题