I have a Node.js Express application that checks for authentication before allowing you onto the homepage. For reasons I cannot figure out it loads my css, but not my javascript after the redirect. Here is the relevant code in my app.js file:
app.get('/',journal.logInCheck,journal.index);
app.get('/logon',journal.logon);
app.post('/authenticate',journal.authenticate);
and here is my journal.js file with dummy auth code:
/***************************************
Logon Form and Authentication Routes
****************************************/
/** Check for Authentication **/
exports.logInCheck = function(req,res,next){
console.log('login check');
if(req.session.auth == true){
console.log('login check = true');
next();
}else{
console.log('login check = false');
res.redirect('/logon');
}
}
/** Logon Form **/
exports.logon = function(req,res){
res.render('logon',{layout:'logonlayout',title:'Logon'});
}
/** Authenticates data after it's been submitted by form above **/
exports.authenticate = function(req,res,next){
console.log('authenticating');
if(req.body.username=="at" && req.body.password=="wm"){
req.session.auth = true;
console.log('logon success');
res.redirect('/');
}else{
req.session.auth = false;
console.log('logon fail');
res.redirect('/logon');
}
}
What's happening is once I authenticate correctly, the program redirects and my node console only shows the two css files being requested, but not the five or six javascript files.
Also I noticed that the url isn't completely rewritten. It shows htt://domain.com:3000/logon#home when it should be showing http://domain.com:3000/#home
As requested here is the layout.jade. This being the only file that loads any javascript and is common to all pages. FYI, the page does load perfectly fine if I remove the logon#home from the url.
!!!
html
head
title= title
link(rel='stylesheet', href='/jqtouch-1.0-b4-rc/themes/css/jqtouch.css', type='text/css', media='screen')
link(rel='stylesheet', href='/stylesheets/style.css', type='text/css', media='screen')
script(src="/jqtouch-1.0-b4-rc/src/lib/zepto.js", charset="utf-8")
script(src="/jqtouch-1.0-b4-rc/src/jqtouch.js", charset="utf-8")
script(src="/javascripts/ajax.js")
script(src="/javascripts/moderniz.js")
script(src="/javascripts/sjcl.js")
script
var jQT = new $.jQTouch({
icon: 'jqtouch.png',
addGlossToIcon: true,
startupScreen: 'jqt_startup.png',
statusBar: 'black'
});
body
block content
Here's the journal.index
exports.index = function(req, res){
res.render('journal', { title: 'Journal App' });
};
Update: I setup a testing app just to isolate the issue. Express redirects do not work properly when the following JQTouch code is present in my jade template.
script
var jQT = new $.jQTouch({
icon: 'jqtouch.png',
addGlossToIcon: true,
startupScreen: 'jqt_startup.png',
statusBar: 'black'
});