Вопрос

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()'});
};
Это было полезно?

Решение

Well I don't know what's wrong with AppFog, but I created an app and ran this code at Nodejitsu and I can confirm it works in 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!

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top