forked from paulovieira/clima-web-madeira
/
routes-dashboard.js
75 lines (56 loc) · 1.84 KB
/
routes-dashboard.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
var Path = require("path");
var Hoek = require("hoek");
var Config = require("config");
var _ = require("underscore");
var rootDir = require('config').get("rootDir");
var Utils = require(Path.join(rootDir, "lib/common/utils"));
var Validate = require(Path.join(rootDir, "lib/common/validate"));
var Pre = require(Path.join(rootDir, "lib/common/prerequisites"));
var internals = {};
internals.config = {};
//internals.config.dashboard = Hoek.applyToDefaults(CommonConfig.config, {
internals.config.dashboard = {
handler: function(request, reply) {
Utils.logCallsite(Hoek.callStack()[0]);
if(!request.auth.isAuthenticated){
Utils.serverLog(["auth"], "requested " + request.path + " but authentication failed - will now redirect to /{lang}/login");
return reply.redirect("/" + request.params.lang + "/login");
}
var context = {
texts: _.indexBy(request.pre.texts, "id"),
textsArray: request.pre.texts,
auth: request.auth,
urlParam1: "dashboard",
showEnglish: request.pre.showEnglish
};
return reply.view('dashboard', {
ctx: context
});
},
validate: {
params: Validate.lang
},
pre: [
[Pre.abortIfInvalidLang],
[Pre.readShowEnglish, Pre.readAllTexts],
[Pre.prepareTextsForView]
]
};
exports.endpoints = [
{
path: "/{lang}/dashboard",
method: "GET",
config: internals.config.dashboard
},
// IMPORTANT: this path below is now being served directly by nginx
{
path: '/dashboard/{anyPath*}',
method: 'GET',
handler: {
directory: { path: Path.join(Config.get("rootDir"), "lib/web/client/dashboard") }
},
config: {
auth: false,
}
},
];