-
Notifications
You must be signed in to change notification settings - Fork 2
/
server.js
77 lines (60 loc) · 2.21 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
global.rootRequire = function(name) {
return require(__dirname + '/' + name);
}
var express = require('express');
var bodyParser = require('body-parser');
var clobWatchController = rootRequire('app/controllers/clobWatch');
var clobProjectController = rootRequire('app/controllers/clobProjects');
var fs = require('fs');
var slobberApp = express();
var router = express.Router();
module.exports = function(clobFileLocation){
slobberApp.get('/', function (req, res){
res.render('index');
});
slobberApp.use('/js', express.static(__dirname + '/public/js'));
slobberApp.use('/css', express.static(__dirname + '/public/css'));
slobberApp.set('view engine', 'jade');
slobberApp.set( 'views', __dirname +'/public');
//end code to be moved to client
router.use(bodyParser.json());
router.route('/clobWatch')
.put(clobWatchController.startClobReq)
.delete(clobWatchController.stopClobReq);
router.route('/clobProject')
.post (clobProjectController.setProjectReq)
.get (clobProjectController.getProjectReq);
router.route('/clobProject/slobGlobs')
.get(clobProjectController.getSlobGlobsReq)
.post(clobProjectController.addSlobGlobReq);
router.route('/clobProject/slobGlobs/remove')
.post(clobProjectController.removeSlobGlobReq);
slobberApp.use('/api', router);
//7562 == slob :)
var slobberServer = slobberApp.listen(7562, function() {
var host = slobberServer.address().address;
var port = slobberServer.address().port;
console.log('slobber server listening at http://%s:%s', host,port);
});
var io = require('socket.io').listen(slobberServer);
io.on('connection', function(socket){
console.log('a user connected');
socket.on('clob', function(msg){
console.log(msg);
});
socket.on('status', function(msg){
io.emit('status', 'on')
});
socket.on('disconnect', function(){
console.log('user disconnected');
});
});
//TODO work out what to do with this
var project = rootRequire('app/models/clobProject');
project.setProject(clobFileLocation);
rootRequire('app/models/clobWatch').setIO(io);
//TODO additionally, make this not stupid
project.changeListeners.push(function(){
fs.writeFile(clobFileLocation, JSON.stringify(project.projectConfig()), function(){console.log("Saved config")});
});
};