forked from jcoppieters/cody-samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js.multivhost_workinprogress
66 lines (55 loc) · 2.02 KB
/
index.js.multivhost_workinprogress
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
//
// Johan Coppieters - jan 2013 - Cody CMS
//
// empty website for Cody CMS
//
//
var cody = require('cody');
var express = cody.express;
var fs = cody.fs;
var mysql = cody.mysql;
var ejs = cody.ejs;
cody.server = express();
var bodyParser = cody.bodyParser;
var expressSession = cody.expressSession;
var multer = cody.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();
});
// setup the config. Order of importance: config.json < -c command line config < environment values
// 1. load default config
cody.config = require('./config-stoerhuus');
cody.config.controllers = require("./controllers/");
// 2. if -c exists, overwrite customized config values
if(process.argv.indexOf("-c") != -1){
var extraConfigFilePath = process.argv[process.argv.indexOf("-c") + 1];
var obj = JSON.parse(fs.readFileSync(extraConfigFilePath, 'utf8'));
Object.keys(cody.config).forEach(function (name) {
cody.config[name] = obj[name] || cody.config[name];
});
}
// 3. overwrite environment variable values
Object.keys(cody.config).forEach(function (name) {
cody.config[name] = process.env[name] || cody.config[name];
});
// startup the web server
cody.startWebApp(cody.server, cody.config, function() {
console.log("Loaded web app....");
console.log("with config (adjust in config.json or by setting as environment variables):")
console.log(cody.config);
var portNr = cody.config.port || 3001;
cody.server.listen(portNr);
console.log('Listening on port ' + portNr);
});
if (!process.stderr.isTTY) {
process.on('uncaughtException', function (err) {
console.error('Uncaught exception : ' + err.stack);
});
}