How To Deploy A React Application On A Static Server
I have a react application build with create-react-app. Its using octoberCMS as the backend fetching data using Axios calls from the frontend. Till now I was developing keeping the build content of react inside a directory named 'react' in the root directory of octoberCMS installation. Hence the URL I was hitting was http://example.com/react/.
The problem is now I am done with the development phase and look forward to deployment. But I want my front-end to be served at http://example.com and backend to be served at http://example.com/backend (backend served as I want). How can I achieve this? I am fairly new to both frameworks.
I have tried keeping the build content along with the rest of the octoberCMS
First build your react app that will give you
vendor.js[third party scripts] and your
app.js[your actual app]
put them in to theme directory
Then In Ocotber CMS make page with URL
/:url? and paste your
index.html content there.
it will be your
root div and
including js html, change path for
js which points to the build js which you put in theme directory.
now what happens when anybody come to site - we are serving same content as we do in dev build - index.html with root tag and needed js
Now if use hit any other url like
https://www.example.com/test/etc it also will be catch by
/:url? (and all other requests) and home page served and our react app will work as we needed.
if any questions please comment.
- → Import statement and Babel
- → should I choose reactjs+f7 or f7+vue.js?
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → .tsx webpack compile fails: Unexpected token <
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → React Native with visual studio 2015 IDE
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
- → How do I determine if a new ReactJS session and/or Browser session has started?
- → Alt @decorators in React-Native
- → How to dynamically add class to parent div of focused input field?