-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
85 lines (69 loc) · 2.07 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
var socketIO = require('socket.io'),
express = require('express'),
objects = [],
mongoose = require('mongoose'),
schemas = require('./mongoschema').schemas(),
app = express.createServer();
io = socketIO.listen(app);
app.configure(function() {
app.set('views', __dirname + '/views')
.use(express.static(__dirname + '/public'))
.set("view options", { layout: false })
.get('/', function(req, res) {
res.render('index.ejs');
})
});
app.listen(80);
mongoose.connect('mongodb://localhost/gridder', onMongoConnected);
for (var i=0; i < schemas.length; i++) {
mongoose.model(schemas[i].name, schemas[i].schema);
}
var Task = mongoose.model('Task');
io.sockets.on('connection', function(client) {
sendSavedTask(client);
client.on('message', function(msg) {
var instance = new Task(a);
instance.save(function (err) {
console.log(err || 'saved');
});
// var id = msg._id;
// delete(msg._id);
// Task.update({_id:id}, msg ,function(err) {
// console.log(err || 'saved');
// });
}
);
client.on('disconnect', function() {onDisconnect(client)});
});
function sendSavedTask(client)
{
var tmpID = '4e489a993bee7c524a000001';
var myTask = Task.findOne({ '_id': tmpID}, function (err, doc){
if (err) {
exitWithError(err);
}
doc = {"parent":[],"child":[],"end_title":"外部公開","tasks":[{"title":"設計","description":"・デザイン\n・プロトタイプ\n","tasks":[{"title":"nontitleaa","tasks":[]}]}],"title":"このアプリ完成まで","_id":"4e489a993bee7c524a000001"}
client.json.send(doc);
});
}
function onDisconnect(client)
{
}
function onMongoConnected(err)
{
if (err) {
exitWithError(err);
} else {
console.log('mongo connect success');
}
}
function nowDate()
{
var d = new Date();
return d.getFullYear() + "-" + (d.getMonth()+1) + "-" + d.getDate()+ " "+ d.getHours()+':' +d.getMinutes()+':' + d.getSeconds();
}
function exitWithError(err)
{
console.log(err);
process.exit(0);
}