-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathfrontpage.js
44 lines (35 loc) · 1.31 KB
/
frontpage.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
var _ = require("underscore");
var cookieTicker = +new Date();
module.exports = function (req, res, next) {
res.locals.Title = "MythExpress";
res.locals.appEnv = appEnv;
if (req.headers.hasOwnProperty("user-agent")) {
var browser = req.headers["user-agent"];
var isIOS = browser.search(/iPad|iPod|iPhone/) != -1;
var isWebApp = isIOS && browser.search(/Mobile/) != -1 && browser.search(/Safari/) == -1;
res.locals.isIOS = isIOS;
res.locals.isWebApp = isWebApp;
} else {
res.locals.isIOS = false;
res.locals.isWebApp = false;
}
// so browser can orient on page load, view transitions, etc.
// some individual routes will change these defaults
res.locals.Context = {
View : req.query.View || "Programs",
Group : req.query.Group || "Default"
};
log.info(req.url);
log.info(req.headers);
if (req.xhr || _.contains(["/mythexpress.appcache", "/js/templates.js", "/js/runtime.js"], req.url)) {
next();
} else {
log.info("Rendering main page");
//log.info("all request cookies:");
//log.info(req.cookies);
if (!req.cookies.mythexpress) {
res.cookie("mythexpress", cookieTicker++, { expires: null, path : "/" });
}
res.render("layout");
}
}