forked from jcoppieters/cody
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
92 lines (70 loc) · 2.47 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
86
87
88
89
90
91
92
//
// 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();
var bodyParser = require('body-parser');
var expressSession = require('express-session');
var multer = require('multer');
// use the new 4.x middleware
cody.server.use(bodyParser());
cody.server.use(expressSession({secret: 'a secret', cookie: { maxAge: 60*60*1000 }}));
cody.server.use(bodyParser.urlencoded({ extended: true }));
cody.server.use(multer());
// 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,
"mailFrom": "[email protected]",
"smtp": "smtpmailer.howest.be",
"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 ' + cody.server.get('port'));
});
});
if (!process.stderr.isTTY) {
process.on('uncaughtException', function (err) {
console.error('Uncaught exception : ' + err.stack);
});
}
};
cody.bootstrap();