Skip to content

Instantly share code, notes, and snippets.

@tmzt
Created March 2, 2011 22:43
Show Gist options
  • Save tmzt/851925 to your computer and use it in GitHub Desktop.
Save tmzt/851925 to your computer and use it in GitHub Desktop.
127.0.0.1 - - [Wed, 02 Mar 2011 22:33:18 GMT] "GET /timothy HTTP/1.0" 500 - "" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.10) Gecko/20100922 Ubuntu/10.10 (maverick) Firefox/3.6.10"
Error: Can't use mutable header APIs after sent.
at ServerResponse.getHeader (http.js:521:11)
at ServerResponse.header (/srv/home/jobitr/development/node_modules/express/lib/response.js:224:17)
at ServerResponse.send (/srv/home/jobitr/development/node_modules/express/lib/response.js:64:17)
at ServerResponse.render (/srv/home/jobitr/development/node_modules/express/lib/view.js:299:10)
at ServerResponse.render (/srv/home/jobitr/development/node_modules/express/lib/view.js:293:10)
at /srv/home/jobitr/development/app.js:560:10
at /srv/home/jobitr/development/lib/UserProvider.js:32:10
at [object Object].<anonymous> (/srv/home/jobitr/development/node_modules/mongodb/lib/mongodb/collection.js:447:35)
at [object Object].emit (events.js:45:17)
at [object Object].<anonymous> (/srv/home/jobitr/development/node_modules/mongodb/lib/mongodb/db.js:83:12)
app.get('/:shorturl/p/:p', function(req, res) {
showpublic(req.params.p, req, res);
});
app.get('/:shorturl/p', function(req, res) {
showpublic('about', req, res);
});
app.get('/:shorturl', function(req, res, next) {
showpublic('about', req, res);
});
function showpublic(p, req, res) {
console.log('session: ', req.session);
var userauth = (typeof(req.session.userauth) != 'undefined') ? req.session.userauth : null;
var shorturl = req.params.shorturl;
urlProvider.findByShort(shorturl, function(error, result) {
if (typeof(result) != 'undefined') {
var profile = result; profile.confirmed = false;
var options = { hostname: req.vhost, user: req.session.userauth, profile: profile};
userProvider.findByEmail(profile.email, function(error, result) {
if (typeof(result) != 'undefined') {
profile.confirmed = result.confirmed;
profile.fullname = result.fullname;
if (typeof(result.profile) != 'undefined') profile.profile = result.profile;
};
if (profile.confirmed) {
res.render('public/'+p, options);
} else {
res.redirect('/'+profile.shorturl+'/confirm');
};
});
} else { res.writeHead(404, 'User not found'); res.end('Jobitr not found'); }
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment