Deploying to Heroku
+ app.use(express.static(path.join(__dirname, 'client/build')));
app.post('/signup', userController.signupUser);
app.post('/login', userController.loginUser);
app.use(jwt({secret: config.secret}))
app.use('/contacts', contactsRouter);
app.use('/users', usersRouter);
// Handles any requests that don't match the ones above
+ app.get('*', (req,res) =>{
+ res.sendFile(path.join(__dirname+'/client/build/index.html'));
+ });
const prodConfig = {
db: env.MONGO_URI,
secret: env.JWT_SECRET
};
"scripts": {
"dev-server": "nodemon --ignore db.json ./bin/www",
"start": "./bin/www",
+ "heroku-postbuild": "cd client && npm install --only=dev && npm install && npm run build"
},
-
Install heroku cli and setup: https://dashboard.heroku.com/apps//deploy/heroku-git
-
heroku config:set MONGO_URI="mongodb+srv://username:password@myproject.mongodb.net/contacts-manager?retryWrites=true"
-
heroku config:set JWT_SECRET=
-
Deploy to Heroku
$ git add .
$ git commit -am "make it better"
$ git push heroku master