I have actually deployed my React-app in the following way:-
- ran the command: npm run build
- Already had db.json file with dummy data.
Context, when I run
json-server --watch db.json -p 3001 -d 2000the entire react-app works on the localhost - installed json-server using npm
- created a server.js file
const jsonServer = require('json-server');
const server = jsonServer.create();
const router = jsonServer.router('db.json');
const middlewares = jsonServer.defaults();
const port = process.env.PORT || 3001;
server.use(middlewares);
server.use(router);
server.listen(port);
- created the app on heroku and pushed it to heroku master
The website for some reason only works when I run
node server.json my local-machine and it is making requests to my localport. if that command isn't running the react-app cannot do the axios request to the DB. I don't know what went wrong. I used the following tutorial for this: https://github.com/jesperorb/json-server-heroku
My suspicions are that in my code I have created a basUrl.js file in which
export const baseUrl = 'http://localhost:3001/';
How should I change this to fix my problem?
Thanks for your help.