Skip to content

Commit

Permalink
Changes for heroku deployment
Browse files Browse the repository at this point in the history
  • Loading branch information
DeadlockDruid committed Sep 24, 2018
1 parent 349c45a commit bd1fe5f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@
"description": "",
"main": "index.js",
"scripts": {
"start": "node server/server.js",
"test": "mocha server/**/*.test.js",
"test-watch": "nodemon --exec 'npm test'"
},
"engines": {
"node": "10.11.0"
},
"author": "",
"license": "ISC",
"dependencies": {
Expand Down
22 changes: 20 additions & 2 deletions server/server.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
let express = require('express');
let bodyParser = require('body-parser');
let { ObjectID } = require('mongodb');

let { mongoose } = require('./db/mongoose');
let { Todo } = require('./models/todo');
let { User } = require('./models/user');

let app = express();
let port = process.env.PORT || 3000;

app.use(bodyParser.json());

Expand All @@ -27,8 +29,24 @@ app.get('/todos', (req, res) => {
}, (e) => res.status(400).send(e));
});

app.listen(3000, () => {
console.log('Started on port: 3000');
app.get('/todos/:id', (req, res) => {
let id = req.params.id;

if (!ObjectID.isValid(id)) {
return res.status(404).send();
}

Todo.findById(id).then((todo) => {
if (!todo) {
return res.status(404).send();
}

res.send(todo);
}).catch((e) => res.status(400).send());
});

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

module.exports = { app };

0 comments on commit bd1fe5f

Please sign in to comment.