-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.js
More file actions
105 lines (80 loc) · 2.31 KB
/
server.js
File metadata and controls
105 lines (80 loc) · 2.31 KB
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
var TRELLO_API_KEY = "2f13d327138dfc7cf2639332254b9bcd"
var express = require('express'),
connect = require('connect'),
batman = require('batman'),
assets = require('connect-assets'),
path = require('path'),
http = require('http'),
https = require('https'),
mongoose = require('mongoose'),
app = express()
app.use(express.bodyParser());
app.use(assets({ src: '.' }));
js.root = 'app'
app.use('/batman', express.static('/usr/local/lib/node_modules/batman/lib'));
app.use('/app/views', express.static(__dirname + '/app/views'));
app.set('views', __dirname + '/app');
app.set('view engine', 'jade');
app.configure('development', function(){
app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
});
var db = mongoose.createConnection('localhost', 'nodejs_test');
var Task = db.model('Task', mongoose.Schema({ name: 'string', idBoard: 'string' }));
var List = db.model('List', mongoose.Schema({ name: 'string', tasks: 'array' }));
app.get('/', function(req, res){
res.render('app', { trello_api_key: TRELLO_API_KEY });
});
//require('./api/tasks')(app, db);
//require('./api/lists')(app, db);
// Tasks
app.post('/tasks', function(req, res){
new Task(req.body.task).save(function (err, task) {
if (err) {
console.error(err)
}
res.json(201, task)
});
});
app.put('/tasks/:id', function(req, res){
Task.findByIdAndUpdate(req.params.id, req.body.task, { upsert: true}, function (err) {
if (err) {
console.error(err)
}
res.status(200).end();
});
});
app.get('/tasks', function(req, res){
Task.find(function (err, tasks) {
if (err) {
console.error(err)
}
res.send(tasks)
})
});
// Lists
app.post('/lists', function(req, res){
new List(req.body.list).save(function (err, list) {
if (err) {
console.error(err)
}
res.json(201, list)
});
});
app.put('/lists/:id', function(req, res){
List.findByIdAndUpdate(req.params.id, req.body.list, { upsert: true}, function (err) {
if (err) {
console.error(err)
}
res.status(200).end();
});
});
app.get('/lists', function(req, res){
List.find(function (err, lists) {
if (err) {
console.error(err)
}
res.send(lists)
})
});
app.listen(3000);
console.log('Listening on port 3000');