i have a problem in my app that i cant resolve
first of all my app:
nodejs 0.8.14 express 3.1 passport-local 0.1
the problem is when i login in passport session the client request the page two times...
i discover that because i put a request var in the url
this in my router
exports.index=function(req,res)
{
console.log('success: '+req.url);
var sesion_usuario=validate(req.params.code_user);//if not valid return null
if(sesion_usuario){
res.render('logged',{title:'Hello'+sesion_usuario})
this in my browser
http://localhost:8000/YOGE7419
this in my app
app.get('/:code_user',routes.index);
and this is what im receiving in my prompt
success: /YOGE7419
success: /YOGE7419
DEBUG: validate error: maxlength not match
and the url transform in this
http://localhost:8000/YOGE7419#sthash.zp1bOY2d.dpbs
why is that??? whats happening between first and second request?? tnx
APP CONFIGURATION
app.configure(function()
{
app.use(express.favicon(__dirname + '/public/images/favicon.png'));
app.set('port', 8000 || process.env.PORT);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set('view options',{layout:false});
//app.use(express.logger('dev'));
app.use(express.bodyParser({uploadDir:'./public/uploads/'}));
app.use(express.cookieParser('nomatherwhatdoyoudobatman'));
app.use(express.session());
app.use(passport.initialize());
app.use(passport.session());
//app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req, res, next){
res.render('404.jade',
{
title: "404 - Page Not Found",
showFullNav: false,
status: 404,
url: req.url
});
});
});
i have a problem in my app that i cant resolve
first of all my app:
nodejs 0.8.14 express 3.1 passport-local 0.1
the problem is when i login in passport session the client request the page two times...
i discover that because i put a request var in the url
this in my router
exports.index=function(req,res)
{
console.log('success: '+req.url);
var sesion_usuario=validate(req.params.code_user);//if not valid return null
if(sesion_usuario){
res.render('logged',{title:'Hello'+sesion_usuario})
this in my browser
http://localhost:8000/YOGE7419
this in my app
app.get('/:code_user',routes.index);
and this is what im receiving in my prompt
success: /YOGE7419
success: /YOGE7419
DEBUG: validate error: maxlength not match
and the url transform in this
http://localhost:8000/YOGE7419#sthash.zp1bOY2d.dpbs
why is that??? whats happening between first and second request?? tnx
APP CONFIGURATION
app.configure(function()
{
app.use(express.favicon(__dirname + '/public/images/favicon.png'));
app.set('port', 8000 || process.env.PORT);
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.set('view options',{layout:false});
//app.use(express.logger('dev'));
app.use(express.bodyParser({uploadDir:'./public/uploads/'}));
app.use(express.cookieParser('nomatherwhatdoyoudobatman'));
app.use(express.session());
app.use(passport.initialize());
app.use(passport.session());
//app.use(express.methodOverride());
app.use(app.router);
app.use(express.static(path.join(__dirname, 'public')));
app.use(function(req, res, next){
res.render('404.jade',
{
title: "404 - Page Not Found",
showFullNav: false,
status: 404,
url: req.url
});
});
});
Share
Improve this question
edited May 7, 2013 at 17:21
andrescabana86
asked May 7, 2013 at 15:39
andrescabana86andrescabana86
1,7888 gold badges32 silver badges56 bronze badges
6
- 2 If you make request with browser, than second request may be init by brwoser for getting /favicon.ico – Eugene Commented May 7, 2013 at 15:42
- i mit favicon and still have a second request – andrescabana86 Commented May 7, 2013 at 15:44
- Do you mean you get double requests when your browser visits the url? console.log('success', req.url) will show you which url is doing the request. If it's a request password makes then you can ignore this ment. – Pickels Commented May 7, 2013 at 17:00
- @Pickels req.url == /YOGE7419 prompt print success: /YOGE7419 success: /YOGE7419 – andrescabana86 Commented May 7, 2013 at 17:18
- do you think its a request password?? – andrescabana86 Commented May 7, 2013 at 17:20
2 Answers
Reset to default 2If express redirects the browser then the browser will send a repeated request (in my experience it was after 5 seconds) if the redirection has not pleted.
By adding a timeout to the redirection's request I was able to avoid the duplicate request:
app.get('/path2', function( req, res ) {
req.connection.setTimeout( 1000 * 60 * 10 ); // ten minutes
console.log('path2');
});
For detailed discussion read here at GitHub Link.
The first request is automatically made by the browser, which requests favicon.ico, and of course, the second request is for the URL (Your URl).
Further More Refer
http://net.tutsplus./tutorials/javascript-ajax/node-js-for-beginners/