UNPKG

2.05 kBJavaScriptView Raw
1var exports = module.exports;
2
3exports.DEFAULT_GITANA_PROXY_SCHEME = "https";
4exports.DEFAULT_GITANA_PROXY_HOST = "api1.cloudcms.com";
5exports.DEFAULT_GITANA_PROXY_PORT = 443;
6
7/**
8 * This version of the cloudcms-server supports CloudFront CDN. Anybody using "api.cloudcms.com" can auto-upgrade
9 * to "api1.cloudcms.com" for the time being as this points to CloudFront.
10 *
11 * In the future, we'll migrate "api.cloudcms.com" to CloudFront and this will no longer be necessary.
12 *
13 * @param host
14 * @returns {*}
15 */
16exports.autoUpgrade = function(hostOrUrl, verbose)
17{
18 // default value if not supplied
19 if (typeof(process.env.CLOUDCMS_API_PREFER_CDN) === "undefined") {
20 process.env.CLOUDCMS_API_PREFER_CDN = "true";
21 process.env.CLOUDCMS_API_PREFER_LB = "false";
22 }
23
24 if (hostOrUrl)
25 {
26 var handleReplaceHost = function(hostOrUrl, oldHost, newHost, verbose, loggerFn)
27 {
28 if (hostOrUrl.indexOf(oldHost) > -1)
29 {
30 if (verbose)
31 {
32 loggerFn(oldHost, newHost);
33 }
34
35 hostOrUrl = hostOrUrl.replace(oldHost, newHost);
36 }
37
38 return hostOrUrl;
39 };
40
41 if (process.env.CLOUDCMS_API_PREFER_CDN === true || process.env.CLOUDCMS_API_PREFER_CDN === "true")
42 {
43 hostOrUrl = handleReplaceHost(hostOrUrl, "api.cloudcms.com", "api1.cloudcms.com", verbose, function(oldHost, newHost) {
44 console.log("Adjusting API connection to use CloudFront: " + oldHost + " to: " + newHost + " for improved edge performance");
45 });
46 }
47 else if (process.env.CLOUDCMS_API_PREFER_LB === true || process.env.CLOUDCMS_API_PREFER_LB === "true")
48 {
49 hostOrUrl = handleReplaceHost(hostOrUrl, "api1.cloudcms.com", "api.cloudcms.com", verbose, function(oldHost, newHost) {
50 console.log("Adjusting API connection to use Load Balancer: " + oldHost + " to: " + newHost);
51 });
52 }
53 }
54
55 return hostOrUrl;
56};
\No newline at end of file