-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
43 lines (32 loc) · 1.09 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
var express = require('express');
var http = require('http');
var path = require('path');
var list = require('./routes/list');
var app = express();
var allowCrossDomain = function(req, res, next) {
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE,OPTIONS');
res.header('Access-Control-Allow-Headers', 'Content-Type, Authorization, Content-Length, X-Requested-With');
if ('OPTIONS' == req.method) {
res.send(200);
}
else {
next();
}
};
// añadir en app config
app.use(allowCrossDomain);
app.set('port', process.env.PORT || 3000);
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
//GET
app.get('/list', list.getList); //Get all the lists
//POST
app.post('/create-entry', list.createEntry); //Create a new entry in the list
//PUT
app.put('/completeTask/:id', list.updateEntry); //Update the status of the entry
app.listen(app.get('port'), function() {
console.log('Port 3000 live, and listening!!!');
});