-
Notifications
You must be signed in to change notification settings - Fork 3
/
app.js
180 lines (154 loc) · 5.18 KB
/
app.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
var server = require("cloudcms-server/server");
var frameworkControllers = require("cloudcms-server/framework/controllers");
var frameworkSockets = require("cloudcms-server/framework/sockets");
if (process.env.CLOUDCMS_NOTIFICATIONS_ENABLED) {
if (!process.env.CLOUDCMS_NOTIFICATIONS_SQS_QUEUE_URL) {
process.env.CLOUDCMS_NOTIFICATIONS_ENABLED = false;
}
if (!process.env.CLOUDCMS_NOTIFICATIONS_SQS_ACCESS_KEY) {
process.env.CLOUDCMS_NOTIFICATIONS_ENABLED = false;
}
if (!process.env.CLOUDCMS_NOTIFICATIONS_SQS_SECRET_KEY) {
process.env.CLOUDCMS_NOTIFICATIONS_ENABLED = false;
}
if (!process.env.CLOUDCMS_NOTIFICATIONS_SQS_REGION) {
process.env.CLOUDCMS_NOTIFICATIONS_ENABLED = false;
}
}
/**
* Default route handlers
*/
server.routes(function(app, callback) {
frameworkControllers.init(app, function(err) {
callback(err);
});
});
/**
* Default socket handlers
*/
server.sockets(function(socket, callback) {
frameworkSockets.init(socket, function(err) {
callback(err);
});
});
/*
// after
server.after(function(app, callback) {
callback();
});
*/
// report
server.report(function(callback) {
console.log("");
console.log("Cloud CMS Virtual Server started! (v" + process.env.CLOUDCMS_APPSERVER_PACKAGE_VERSION + ")");
console.log("");
var cpuCount = require('os').cpus().length;
// provide some debug info
console.log("");
console.log("Node Version: " + process.version);
console.log("Server Mode: " + process.env.CLOUDCMS_APPSERVER_MODE);
console.log("Server Base Path: " + process.env.CLOUDCMS_APPSERVER_BASE_PATH);
console.log("Gitana Scheme: " + process.env.GITANA_PROXY_SCHEME);
console.log("Gitana Host: " + process.env.GITANA_PROXY_HOST);
console.log("Gitana Port: " + process.env.GITANA_PROXY_PORT);
console.log("CPU Count: " + cpuCount);
var virtualHost = null;
if (process.env.CLOUDCMS_VIRTUAL_HOST) {
virtualHost = process.env.CLOUDCMS_VIRTUAL_HOST;
}
if (!virtualHost && process.env.CLOUDCMS_VIRTUAL_HOST_DOMAIN) {
virtualHost = "*." + process.env.CLOUDCMS_VIRTUAL_HOST_DOMAIN;
}
if (virtualHost)
{
console.log("Virtual Host: " + virtualHost);
}
console.log("Store Configuration: " + process.env.CLOUDCMS_STORE_CONFIGURATION);
console.log("Broadcast Provider: " + process.env.CLOUDCMS_BROADCAST_TYPE);
console.log("Cache Provider: " + process.env.CLOUDCMS_CACHE_TYPE);
console.log("Temp Directory: " + process.env.CLOUDCMS_TEMPDIR_PATH);
console.log("LaunchPad Mode: " + process.env.CLOUDCMS_LAUNCHPAD_SETUP);
console.log("Max Files Detected: " + process.env.CLOUDCMS_MAX_FILES);
console.log("Virtual Host Enabled: " + config.virtualHost.enabled);
console.log("");
console.log("Web Server: http://localhost:" + process.env.PORT);
console.log("");
callback();
});
// start the server
// use xhr-polling since socket connections seem to fail after awhile?
var config = {
"setup": "single",
"virtualHost": {
"enabled": false
},
"virtualDriver": {
"enabled": false
},
"wcm": {
"enabled": true,
"cache": false
},
"serverTags": {
"enabled": true
},
"autoRefresh": {
"log": true
},
"welcome": {
"enabled": true,
"file": "index.html"
}
};
if (process.env.CLOUDCMS_NOTIFICATIONS_ENABLED)
{
config.notifications = {
"enabled": process.env.CLOUDCMS_NOTIFICATIONS_ENABLED,
"type": "sqs",
"configuration": {
"queueUrl": process.env.CLOUDCMS_NOTIFICATIONS_SQS_QUEUE_URL,
"accessKey": process.env.CLOUDCMS_NOTIFICATIONS_SQS_ACCESS_KEY,
"secretKey": process.env.CLOUDCMS_NOTIFICATIONS_SQS_SECRET_KEY,
"region": process.env.CLOUDCMS_NOTIFICATIONS_SQS_REGION
}
};
}
// configure virtual driver
if (process.env.CLOUDCMS_VIRTUAL_DRIVER_CLIENT_KEY &&
process.env.CLOUDCMS_VIRTUAL_DRIVER_CLIENT_SECRET &&
process.env.CLOUDCMS_VIRTUAL_DRIVER_AUTHGRANT_KEY &&
process.env.CLOUDCMS_VIRTUAL_DRIVER_AUTHGRANT_SECRET)
{
config.virtualHost.enabled = true;
config.virtualDriver.enabled = true;
config.virtualDriver.clientKey = process.env.CLOUDCMS_VIRTUAL_DRIVER_CLIENT_KEY;
config.virtualDriver.clientSecret = process.env.CLOUDCMS_VIRTUAL_DRIVER_CLIENT_SECRET;
config.virtualDriver.username = process.env.CLOUDCMS_VIRTUAL_DRIVER_AUTHGRANT_KEY;
config.virtualDriver.password = process.env.CLOUDCMS_VIRTUAL_DRIVER_AUTHGRANT_SECRET;
}
// auto-configure stores
if (!process.env.CLOUDCMS_STORE_CONFIGURATION)
{
if (config.virtualHost.enabled)
{
process.env.CLOUDCMS_STORE_CONFIGURATION = "net-development";
}
else
{
process.env.CLOUDCMS_STORE_CONFIGURATION = "default";
}
}
// support for custom.js file
var ignitionFunction = function(server, config, callback)
{
callback();
};
var fs = require("fs");
var exists = fs.existsSync("custom.js");
if (exists)
{
ignitionFunction = require("./custom.js").init;
}
ignitionFunction(server, config, function() {
server.start(config);
});