forked from ricca509/backbonejs-comments
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
29 lines (25 loc) · 942 Bytes
/
Copy pathserver.js
File metadata and controls
29 lines (25 loc) · 942 Bytes
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
var express = require('express'),
path = require('path'),
comments = require('./controllers/comments');
var app = express();
// Set server port
app.set('port', process.env.PORT || 3000);
// Set folder to serve static files
app.use('/', express.static(path.join(__dirname, 'public')));
// Log routes
app.use(express.logger());
app.use(express.bodyParser());
// REST API routes definition
// GET to /comments returns all comments
app.get('/comments', comments.getAll);
// GET to /comments/:id returns a single comment
app.get('/comments/:id', comments.getOne);
// POST to /comments adds a comment
app.post('/comments', comments.add);
// PUT to /comments/:id modifies an existing comment
app.put('/comments/:id', comments.update);
// DELETE to /comments/:id deletes an existing comment
app.delete('/comments/:id', comments.delete);
app.listen(app.get('port'), function() {
console.log('Server listening on port ' + app.get('port'));
});