forked from sf-wdi-24/express-todo-app
-
Notifications
You must be signed in to change notification settings - Fork 48
/
Copy pathserver.js
90 lines (73 loc) · 2.31 KB
/
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
// 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'));
/************
* DATABASE *
************/
// our database is an array for now with some hardcoded values
var todos = [
{ _id: 7, task: 'Laundry', description: 'Wash clothes' },
{ _id: 27, task: 'Grocery Shopping', description: 'Buy dinner for this week' },
{ _id: 44, task: 'Homework', description: 'Make this app super awesome!' }
];
/**********
* ROUTES *
**********/
/*
* HTML Endpoints
*/
app.get('/', function homepage(req, res) {
res.sendFile(__dirname + '/views/index.html');
});
/*
* JSON API Endpoints
*
* The comments below give you an idea of the expected functionality
* that you need to build. These are basic descriptions, for more
* specifications, see the todosTest.js file and the outputs of running
* the tests to see the exact details. BUILD THE FUNCTIONALITY IN THE
* ORDER THAT THE TESTS DICTATE.
*/
app.get('/api/todos/search', function search(req, res) {
/* This endpoint responds with the search results from the
* query in the request. COMPLETE THIS ENDPOINT LAST.
*/
});
app.get('/api/todos', function index(req, res) {
/* This endpoint responds with all of the todos
*/
});
app.post('/api/todos', function create(req, res) {
/* This endpoint will add a todo to our "database"
* and respond with the newly created todo.
*/
});
app.get('/api/todos/:id', function show(req, res) {
/* This endpoint will return a single todo with the
* id specified in the route parameter (:id)
*/
});
app.put('/api/todos/:id', function update(req, res) {
/* This endpoint will update a single todo with the
* id specified in the route parameter (:id) and respond
* with the newly updated todo.
*/
});
app.delete('/api/todos/:id', function destroy(req, res) {
/* This endpoint will delete a single todo with the
* id specified in the route parameter (:id) and respond
* with success.
*/
});
/**********
* SERVER *
**********/
// listen on port 3000
app.listen(3000, function() {
console.log('Server running on http://localhost:3000');
});