简体   繁体   中英

Node.js express server on appfog: sessions lost on page refresh when using chrome on android

I am so confused. I made an express app like this:

$ express -s -e sessionTest

Then I edited the routes a little to set a session var, check it and delete it. I run the server on my local machine, and any browser I use (Chrome, Firefox, Android Chrome, Android Dolphin) works as expected. However, as soon as I upload this to appfog, Chrome on Android fails to keep the same session over a page load. You can test this yourself, here is my hosted app on appfog:

kyle.aws.af.cm

The fist page you come to will set a session var. There is a link on that page to check if the session var is set and another link to destroy your session. Chrome for Android never reports that you have set the session var. Again this only doesn't work with Chrome for Android when my app is on appfog. Any other browser seems to work fine regardless if this app is on appfog or not.

Is this an appfog bug? Is this a Chrome for Android bug? Is this an express or connect bug? Or am I doing something wrong?

My code:

app.js

var express = require('express')
, routes = require('./routes')
, http = require('http')
, path = require('path');

var app = express();

app.configure(function(){
  app.set('port', process.env.VMC_APP_PORT || process.env.PORT || 1337);
  app.set('views', __dirname + '/views');
  app.set('view engine', 'ejs');
  app.use(express.favicon());
  app.use(express.logger('dev'));
  app.use(express.bodyParser());
  app.use(express.methodOverride());
  app.use(express.cookieParser('secret'));
  app.use(express.session());
  app.use(app.router);
  app.use(express.static(path.join(__dirname, 'public')));
});

app.configure('development', function(){
  app.use(express.errorHandler());
});

app.get('/', routes.index);
app.get('/session', routes.session);
app.get('/destroy', routes.kill);

http.createServer(app).listen(app.get('port'), function(){
  console.log("Express server listening on port " + app.get('port'));
});

./routes/index.js

exports.index = function(req, res){
  req.session.test = 1;
  res.render('index', { title: 'I set the session var test to 1' });
};

exports.session = function(req, res){
  if(req.session.test === 1) {
    res.render('index', {title: 'the session var test is 1! :)'});
  } else {
    res.render('index', {title: 'the session var test is not 1!!!!!! >:('});
  }
};

exports.kill = function(req, res){
  req.session.destroy();
  res.render('index', {title: 'I called session.destroy()'});
};

好吧,我不知道AppFog有什么问题,但是我创建了一个应用程序并在Nodejitsu上运行了此代码,并且可以确认它可以在Chrome @ Android 4.1.2中运行: http ://testforso.jit.su/

I have the same issue! Don't know what to try else. My app works perfectly on localhost. But when I deploy it on AppFog noting works. I've created a ticket . on the AppFog.

Like yawn I deployed my app on Nodejutsu and it works perfectly!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM