forked from jcoppieters/cody
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
85 lines (64 loc) · 2.15 KB
/
index.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
//
// Johan Coppieters - jan 2013 - jWorks
//
//
var express = require('express');
var fs = require('fs');
var mysql = require('mysql');
var ejs = require('ejs');
var cody = require('./cody');
cody.server = express();
// cookies are encrypted, so we need a pass phrase
cody.server.use(express.bodyParser());
cody.server.use(express.cookieParser("a secret"));
cody.server.use(express.cookieSession());
// startup a routing for all static content of cody (images, javascript, css)
cody.server.get("/cody/static/*", function (req, res) {
var fileserver = new cody.Static(req, res, "");
fileserver.serve();
});
// startup a routing for the unit tests
cody.server.all("/cody/*", function (req, res) {
var aPath = new cody.Path("cody/en/test", "en");
var aContext = new cody.Context(aPath, undefined, undefined, req, res);
res.render("../cody/views/front/index.ejs", { context: aContext });
});
// startup all the web applications
cody.bootstrap = function () {
// startup all the web applications
var connection = mysql.createConnection({
host: "localhost",
user: "cody", password: "ydoc",
database: "cody"
})
connection.connect();
connection.query("SELECT * FROM websites WHERE active='Y' AND ownerconfirmed='Y' ORDER BY id", function(err, rows, fields) {
if(err) throw err;
cody.Application.each(rows, function(next){
var row = this;
cody.startWebApp(cody.server, {
"name": row.name,
"version": row.version,
"defaultlanguage": row.defaultlanguage,
"hostnames" : row.hostname,
"dbuser": row.dbuser,
"dbpassword": row.dbpassword,
"dbhost": row.dbhost,
"datapath": row.datapath,
"db": row.db,
"controllers": require("./" + row.name + "/controllers/")
}, next);
}, function() {
console.log("Loaded all apps....");
connection.end();
cody.server.listen(3000);
console.log('Listening on port 3000');
});
});
if (!process.stderr.isTTY) {
process.on('uncaughtException', function (err) {
console.error('Uncaught exception : ' + err.stack);
});
}
};
cody.bootstrap();