-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
91 lines (76 loc) · 1.96 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
var express = require('express')
, rendr = require('rendr')
, config = require('config')
, _ = require('underscore')
, less = require('less-middleware')
, request = require('request')
, q = require('q')
, app = express();
/**
* Initialize Express middleware stack.
*/
app.use(express.compress());
app.use(function (req, res, next) {
request('http://css.optcentral.com/colors/' + config.appData.user.companyId + '.json', function (error, response, body) {
req.colors = _.values(JSON.parse(body).colors);
next();
});
});
app.use(function (req, res, next) {
request('http://qa.optcentral.com/optportal/services/userInfo/' + config.appData.user.login + '.json', function (error, response, body) {
config.appData.user.companyName = JSON.parse(body).user.companyName;
next();
});
});
app.use(less(__dirname + '/assets/less/generic-abc', {
force: true,
dest: __dirname + '/public',
preprocess: {
path: function(pathname, req) {
return pathname.replace('/css/', '/');
},
less: function(src, req) {
var colors = _.map(req.colors, function(value, key) {
return '@color_' + (key + 1) + ':#' + req.colors[key];
}).join(';') + ';';
return colors + src;
}
}
}));
app.use(express.static(__dirname + '/public'));
app.use(express.logger());
app.use(express.bodyParser());
/**
*
*/
/**
* Initialize our Rendr server.
*/
var server = rendr.createServer({
dataAdapterConfig: config.api,
appData: config.appData
});
/**
*
*/
app.use(server);
/**
* Start the Express server.
*/
function start(){
var port = process.env.PORT || config.server.port;
app.listen(port);
console.log("server pid %s listening on port %s in %s mode",
process.pid,
port,
app.get('env')
);
}
/**
* Only start server if this script is executed, not if it's require()'d.
* This makes it easier to run integration tests on ephemeral ports.
*/
if (require.main === module) {
start();
}
exports.app = app;