-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
98 lines (84 loc) · 2.69 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
91
92
93
94
95
96
97
var express = require('express'),
nko = require('nko')('LkbXCCkD9H9HndHX'),
path = require('path'),
eyes = require('eyes'),
_ = require('underscore'),
browserify = require('browserify'),
crypto = require('crypto'),
MindmapProvider = require('./lib/mindmap-provider'),
SocketServer = require('./lib/socket-server'),
server, socketServer, mindmapProvider;
process.addListener('uncaughtException', function (err, stack) {
console.log('Caught exception: ' + err + '\n' + err.stack);
});
mindmapProvider = new MindmapProvider();
server = express.createServer();
server.configure(function configureAppAndMiddleware() {
server.set('view engine', 'jade');
server.set('view', path.join(__dirname, 'views'));
server.use(express.bodyParser());
server.use(express.cookieParser());
server.use(express.session({ secret: 'LkbXCCkD9H9HndHX' }));
server.use(express.static(path.join(__dirname, 'public')));
server.use(browserify({
require: {
'index': path.join(__dirname, 'client/index'),
'util': path.join(__dirname, 'client/util'),
'mindmap': path.join(__dirname, 'client/mindmap'),
'bubble': path.join(__dirname, 'client/bubble'),
'dispatcher': path.join(__dirname, 'client/dispatcher'),
'receiver': path.join(__dirname, 'client/receiver'),
'user-receiver': path.join(__dirname, 'client/user-receiver'),
'promptFactory': path.join(__dirname, 'client/promptFactory'),
}
}));
});
server.get('/', function showHomePage(req, res) {
var mindmaps;
mindmapProvider.all(function(err, mindmaps) {
res.render('index.jade', {
locals: {
flash: req.flash(),
mindmaps: mindmaps
},
layout : 'index-layout.jade'
});
});
});
server.get('/mindmap/:name', function(req, res) {
res.render('workspace.jade');
});
server.get('/info', function(req, res){
res.render('info.jade',{layout : 'index-layout.jade'});
});
server.post('/create', function(req, res) {
var provider = mindmapProvider;
mindmapProvider.all(function(err, mindmaps) {
var response = res,
request = req,
exists = _.detect(mindmaps, function(mindmap) {
return mindmap.name == req.body.mindmapname;
});
eyes.inspect(mindmaps);
if (exists) {
req.flash('error', 'A mindmap with that name already exists, ' +
'try another one');
res.redirect('/');
}
else if (!/^[A-Za-z0-9]+$/.test(req.body.mindmapname)) {
req.flash('error', 'A mindmap name must be alphanumeric' +
'try another one');
res.redirect('/');
} else {
provider.add({
name: req.body.mindmapname,
bubbles: [],
connections: []
});
res.redirect('/mindmap/' + req.body.mindmapname);
}
});
});
server.listen(+process.env.PORT || 8080);
socketServer = new SocketServer(server);
socketServer.initialize();