forked from sf-wdi-24/express-todo-app
-
Notifications
You must be signed in to change notification settings - Fork 48
/
server.js
49 lines (31 loc) · 1020 Bytes
/
server.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// require express and other modules
var express = require('express'),
app = express(),
bodyParser = require('body-parser');
// configure bodyParser (for receiving form data)
app.use(bodyParser.urlencoded({ extended: true }));
// serve static files from public folder
app.use(express.static(__dirname + '/public'));
// set view engine to hbs (handlebars)
app.set('view engine', 'hbs');
// add controllers
var controllers = require('./controllers');
// HOMEPAGE ROUTE
app.get('/', function (req, res) {
res.render('index');
});
// API ROUTES
// get all todos
app.get('/api/todos', controllers.todos.todoIndex);
// create new todo
app.post('/api/todos', controllers.todos.todoCreate);
// get one todo
app.get('/api/todos/:id', controllers.todos.todoShow);
// update todo
app.put('/api/todos/:id', controllers.todos.todoUpdate);
// delete todo
app.delete('/api/todos/:id', controllers.todos.todoDestroy);
// listen on port 3000
app.listen(3000, function() {
console.log('server started');
});