Click here for more details
- Clone the repo
git clone https://github.com/CSIS-3380-001/final-project
- Install server dependencies
cd ./server && npm i
- Create
.env
file inside./server
directory (./server/.env
) - Add following lines in the file
PORT=8081 DB_URI="mongodb+srv://root:<passwd>@cluster0.dg4ocjz.mongodb.net/?retryWrites=true&w=majority"
- Start server using
npm start
- Install client dependencies
cd ./client && npm i
- Start server usign
npm start
- Make sure both the client and server are in the same repository. Just like this one.
/
- client
- server
- Now make sure all the API calls from the client redirects to the server instance. For this, we will use a service where we will mention generic GET, POST, PUT and DELETE methods. Same like we have in this repo
/client/src/services/api.js
The main benefit of using this service is that we can redirect all the client side requests to any server endpoint. All we need to do is just import this service in our code and use this service to hit the API.
import API from 'services/api.js' # Import the service
API.post() # Use the service
- On the server side, all we need to do is to make the build directory of the client is the root of the public directory.
// Routes
app.use(router);
app.use('/cars', carRouter);
// Make sure its after all the routes imported i.e the last route
app.get('*', (req, res) => {
res.sendFile(path.join(__dirname, '../client/build', 'index.html'));
});
- We will build the project and deploy it on render.com. Check
./build.sh
for more details.