Skip to content

Commit

Permalink
first deploy setting to heroku
Browse files Browse the repository at this point in the history
  • Loading branch information
suulola committed May 6, 2019
1 parent 5d1d46d commit 06ac3c4
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"server": "nodemon server.js",
"client": "npm start --prefix client",
"client-install": "npm install --prefix client",
"dev": "concurrently \"npm run server\" \"npm run client\""
"dev": "concurrently \"npm run server\" \"npm run client\"",
"heroku-postbuild": "NPM_CONFIG_PRODUCTION=false npm install --prefix client && npm run build --prefix client"
},
"keywords": [
"developers"
Expand Down
14 changes: 7 additions & 7 deletions routes/api/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ router.get(
.then(profile => {
if (!profile) {
errors.noprofile = "There is no profile for this user";
res.status(404).json(errors);
return res.status(404).json(errors);
}
res.json(profile);
return res.json(profile);
})
.catch(err => res.status(404).json(err));
}
Expand All @@ -54,7 +54,7 @@ router.get("/all", (req, res) => {
errors.noprofile = "No profile exist";
return res.status(404).json(errors);
}
res.json(profiles);
return res.json(profiles);
})
.catch(err => res.status(404).json({ noprofile: "No profile exist" }));
});
Expand All @@ -69,9 +69,9 @@ router.get("/handle/:handle", (req, res) => {
.then(profile => {
if (!profile) {
errors.noprofile = "There is no profile for this user";
res.status(400).json(errors);
return res.status(400).json(errors);
}
res.json(profile);
return res.json(profile);
})
.catch(err => res.status(404).json(err));
});
Expand All @@ -87,7 +87,7 @@ router.get("/user/:user_id", (req, res) => {
.then(profile => {
if (!profile) {
errors.noprofile = "There is no profile for this user";
res.status(404).json(errors);
return res.status(404).json(errors);
}
res.json(profile);
})
Expand Down Expand Up @@ -146,7 +146,7 @@ router.post(
Profile.findOne({ handle: profileFields.handle }).then(profile => {
if (profile) {
errors.handle = "That profile already exists";
return res.status(400).json(errors);
return res.status(400).json(errors);
}
new Profile(profileFields).save().then(profile => res.json(profile));
});
Expand Down
2 changes: 1 addition & 1 deletion routes/api/users.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ router.post("/login", (req, res) => {
}
});
})
.catch(err => console.log(err));
.catch(err => res.status(404).json(err));
});

router.get(
Expand Down
10 changes: 10 additions & 0 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const express = require("express");
const mongoose = require("mongoose");
const bodyParser = require("body-parser");
const passport = require("passport");
const path = require('path')

const app = express();
const port = process.env.PORT || 5000;

Expand Down Expand Up @@ -35,4 +37,12 @@ app.use("/api/users", users);
app.use("/api/profile", profile);
app.use("/api/posts", posts);

// Serve static assets in production
if(process.env.NODE_ENV === 'production') {
app.use(express.static("client/build"))
app.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname, 'client', 'build', 'index.html' ))
})
}

app.listen(port, () => console.log(`Server started on port ${port}`));

0 comments on commit 06ac3c4

Please sign in to comment.