-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathideino.js
95 lines (90 loc) · 2.91 KB
/
ideino.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
// requires
var express = require('express');
app = express();
var server = require('http').createServer(app),
io = require('socket.io').listen(server,{log:false}),
fs = require('fs'),
path = require('path'),
ejs = require('ejs-locals'),
childprocs = require('./lib/childprocs'),
os = require('os');
io.set('log level',3);
// ideino config
//ST find ip addresses
var interfaces = os.networkInterfaces();
var addresses = [];
for (k in interfaces) {
for (k2 in interfaces[k]) {
var address = interfaces[k][k2];
if (address.family == 'IPv4' && !address.internal) {
addresses.push(address.address)
}
}
}
if(addresses.length == 0){
addresses.push("localhost");
}
//ST find ip addresses
var ideinoConfig = {};
if (fs.existsSync('./ideino.json')) {
ideinoConfig = require('./ideino.json');
}
// set up default prj dir - used in the absence of a 'path' query string
if (!ideinoConfig.projectsDir) ideinoConfig.projectsDir = path.join(__dirname, 'ideino/projects/user');
if (!ideinoConfig.templatesDir) ideinoConfig.templatesDir = path.join(__dirname, 'ideino/templates')
//ST: changing loopback or localhost to real ip address
if (!ideinoConfig.framesUrl1) ideinoConfig.framesUrl1 = "http://"+addresses[0]+":3000";
if (!ideinoConfig.framesUrl2) ideinoConfig.framesUrl2 = "http://"+addresses[0]+":8080/debug?port=5858";
//ST: changing loopback or localhost to real ip address
app.set('ideinoConfig', ideinoConfig);
// initialize locals
app.locals({
metaTitle: 'Ideino',
templates: fs.readFileSync(path.join(__dirname,'./public/html/templates.html'))
});
// register .html extension
app.engine('html', ejs);
// configure
var port = process.env.PORT || 2424;
var sessionStore = new express.session.MemoryStore({
reapInterval: 60000 * 10
});
app.configure(function() {
app.use(express.favicon( path.join(__dirname,'/public/favicon.ico')));
app.set('port', port);
app.set('views', path.join(__dirname, 'views'));
app.set('view engine', 'html');
app.use(express.cookieParser());
app.use(express.session({
store: sessionStore,
secret: '5up3453c43t',
key: 'sid'
}));
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.favicon());
app.use(express.compress());
if (ideinoConfig.users) {
app.use(express.basicAuth(function(user, pass, callback) {
callback(null, ideinoConfig.users[user] == pass);
}));
}
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
});
app.configure('development', function() {
app.use(express.logger('dev'));
app.use(express.errorHandler());
});
process.on('uncaughtException', function(err) {
console.error(err.stack);
});
// routing
require('./lib/routing').configure();
// initialize server / start listening
server.listen(port, function() {
console.log('Listening on ' + port);
});
// child processes
childprocs.connect(io, sessionStore);
app.set('childprocs', childprocs);