Skip to content

Commit

Permalink
fixing root site
Browse files Browse the repository at this point in the history
  • Loading branch information
bvallelunga committed May 1, 2014
1 parent 8a06f3f commit b9337aa
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 35 deletions.
20 changes: 9 additions & 11 deletions routes/globals.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
module.exports = function(req, res, next) {
//Set Server Root For Non Express Calls
req.session.server = req.protocol + "://" + req.host;
req.verified = (req.host.split(".").slice(-2).join(".") == config.general.security);

if(!config.general.production || !config.random) {
config.random = Math.floor((Math.random()*1000000)+1);
}
req.server = req.protocol + "://" + req.host;

//Header Config
res.header("Server", config.general.company);
Expand All @@ -14,6 +9,12 @@ module.exports = function(req, res, next) {
res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');


//Set Random Number
if(!config.general.production || !config.random) {
config.random = Math.floor((Math.random()*1000000)+1);
}

//Device Info
var device = req.device.type.toLowerCase();
req.mobile = ["phone", "tablet"].indexOf(device) != -1;
Expand Down Expand Up @@ -57,7 +58,7 @@ module.exports = function(req, res, next) {
//Locals
res.locals.csrf = (req.csrfToken) ? req.csrfToken() : "";
res.locals.production = config.general.production;
res.locals.host = req.session.server;
res.locals.host = req.server;
res.locals.hostname = req.host;
res.locals.title = "";
res.locals.site_title = config.general.company;
Expand All @@ -66,7 +67,7 @@ module.exports = function(req, res, next) {
res.locals.company = config.general.company;
res.locals.config = {};
res.locals.icons = config.icons;
res.locals.user = req.session.user;
res.locals.user = (req.session) ? req.session.user : {};
res.locals.title_first = true;
res.locals.location = req.location;
res.locals.random = "?rand=" + config.random;
Expand All @@ -89,7 +90,4 @@ module.exports = function(req, res, next) {
} else {
res.redirect(req.protocol + "://" + req.host.split(".").slice(1).join(".") + req.path);
}

//Session Save
req.session.save();
}
4 changes: 2 additions & 2 deletions routes/track/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,12 @@ exports.survey = function(req, res, next) {
assests: {
css: $.map(req.css.renderTags("survey").split("\n"), function(script) {
if(script) {
return req.session.server + $(script).attr("href");
return req.server + $(script).attr("href");
}
}),
js: $.map(req.js.renderTags("survey").split("\n"), function(script) {
if(script) {
return req.session.server + $(script).attr("src");
return req.server + $(script).attr("src");
}
})
},
Expand Down
43 changes: 21 additions & 22 deletions server.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,24 +56,34 @@ app.configure(function() {
app.use(slashes(true));
app.use(device.capture());

//Setup Subdomains
async.each(config.general.subdomains, function(subdomain, next) {
if(subdomain != "") {
subdomains.use(subdomain);
}

next();
}, function() {
app.use(subdomains.middleware);
});

//Logger & Cookie
app.use(express.logger("dev"));
app.use(express.compress());
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser(config.cookies.session.secret));
app.use(express.session({
key: config.cookies.session.key,
secret: config.cookies.session.secret,
store: new RedisStore({
client: lib.redis
})
}));

//Setup CSRF
app.use(function(req, res, next) {
if(/^\/((?!track).)*$/.exec()) {
express.csrf()(req, res, next);
if(/^\/(?!track)/.test(req.url)) {
express.session({
key: config.cookies.session.key,
secret: config.cookies.session.secret,
store: new RedisStore({
client: lib.redis
})
})(req, res, function() {
express.csrf()(req, res, next);
});
} else {
next();
}
Expand All @@ -82,17 +92,6 @@ app.configure(function() {
//Initialize Models
app.use(lib.models);

//Setup Subdomains
async.each(config.general.subdomains, function(subdomain, next) {
if(subdomain != "") {
subdomains.use(subdomain);
}

next();
}, function() {
app.use(subdomains.middleware);
});

//Setup Express Error Handling
app.use(require("./routes/error").express);

Expand Down

0 comments on commit b9337aa

Please sign in to comment.