This repository has been archived by the owner on Jan 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
Copy pathroutes.js
72 lines (61 loc) · 1.76 KB
/
routes.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
var http = require("http"),
url = require('url'),
i18n = require("webmaker-i18n"),
path = require("path"),
template = require("url-template"),
version = require("./package").version,
wts = require("webmaker-translation-stats");
module.exports.analytics = function(req, res, next) {
res.type("text/javascript; charset=utf-8");
res.render("googleanalytics.js");
};
module.exports.embedShellHandler = function(req, res, next) {
// check if this is a goggles make
var result = req.path.match(/^\/(.*)\/.*$/);
if (result === null) {
var err = {
message: req.gettext("You found a loose thread!"),
status: 404
};
res.status(err.status);
return res.render("error.html", err);
}
if (result[1] == "goggles") {
return next();
}
res.render("embed-shell.html");
};
module.exports.healthCheck = function(req, res, next) {
var healthcheckObject = {
http: "okay",
version: version
};
wts(i18n.getSupportLanguages(), path.join(__dirname, "locale"), function(err, data) {
if(err) {
healthcheckObject.locales = err.toString();
} else {
healthcheckObject.locales = data;
}
res.json(healthcheckObject);
});
};
module.exports.proxyHandler = function(req, res, next) {
var proxyReq = http.get(res.locals.proxyPath, function(proxyRes) {
if (proxyRes.statusCode != 200) {
proxyReq.abort();
return next("route");
}
var contentType = proxyRes.headers["content-type"];
if (contentType && contentType !== "binary/octet-stream") {
res.type(contentType);
} else {
res.type("text/html; charset=UTF-8");
}
proxyRes.on("error", function(err) {
next(err);
});
proxyRes.pipe(res);
}).on("error", function(err) {
next(err);
});
};