Question

I am having troubles with getting IE8/9 to work with the way my app is set out. Initially I was using express to store my session var, this worked with a url path like '/broadcast/12343' however when view in IE8 nothing renders. If I change it to '/#/broadcast/12343' IE renders correctly however express doesn't read the hash var so can't set the session which in this case would be 12343. I either need to change the sessions to be created and checked in angular or preferably get IE8 working without the hash in the URL.

And yes I have included ngRoute and the CDN file for angular-route.min.js

My server.js

      app.configure(function(){
        app.set('views', __dirname + '/views');
        app.set('view engine', 'jade');
        app.set('view options', {
          layout: false
        });
        app.use( express.cookieParser() );
        app.use(express.session({
              store: new MongoStore({
                url: 'mongodb://URL/'
              }),
              maxAge  : new Date(Date.now() + (3600000 * 24 *365)), //1 year
              expires : new Date(Date.now() + (3600000 * 24 *365)), //1 year
              secret: '1234567890QWERTY',
              httpOnly: false 
        }));
        app.use(express.favicon());
        app.use(express.bodyParser());
        app.use(express.methodOverride());
        app.use(express.static(__dirname + '/public'));
        app.use(app.router);
      });

      app.configure('development', function(){
        app.use(express.errorHandler({ dumpExceptions: true, showStack: true }));
      });

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

      app.get('/partials/:name', routes.partials);
      app.get('/event/:eventid', routes.event);
      app.post('/registrant/create', routes.register);

      app.get('/broadcast/*', function (req, res) {

          var eventid = req.url.replace("/broadcast/", "");///ie 12343
          if(!req.session.eventids) req.session.eventids = [];

              if (req.session.eventids.indexOf(eventid) > -1) {

                 res.render('index');

          } else {

             res.render('signup', {
                    title:"Signup",
                    eventid:eventid
                });
          }
      });

      app.get("*",  routes.index);

app.js

var app = angular.module('myApp', ['myApp.filters','ngRoute','myApp.directives','myApp.services','snap']);

routes/index.js

   var Event = require('../models/events');
   var mongoose= require('mongoose');
   var url= require('url');

  exports.index = function(req, res){
    res.render('index');
  };

  exports.partials = function (req, res) {
    var name = req.params.name;

     res.render('partials/' + name);
  };

  exports.event = function (req, res) {

    var id = req.params.eventid;

    var self = this;

    Event.findOne({managerId:id}, function(err, docs){
        res.json(docs);   
    }); 
  };

  exports.register = function (req, res) {

    var input = JSON.stringify(req.body);
    var ip = req.headers['x-forwarded-for'] || req.connection.remoteAddress;

    new Registrant({
        eventid:req.body.eventid,
        fields:input,
        ip :ip,
        updated_at : Date.now()

    }).save( function ( err, registrant, count ){

      if( err ) return next( err );
      req.session.username = req.body.firstname + req.body.lastname + req.body.eventid;

    });

    if (req.session.eventids.indexOf(req.body.eventid) < 0) 
        req.session.eventids.push(req.body.eventid);

    res.redirect('/broadcast/'+req.body.eventid);//eventid rendered in form on signup page

  };

Also my layout.jade

   html#ng-app(data-ng-app="myApp"  xmlns:ng="http://angularjs.org")
    ......
Était-ce utile?

La solution 2

There was an error with the include of files, i needed an absolute path rather than relative, thanks for your help though.

Autres conseils

Is app.get('/broadcast/*' designed to return an Angular partial?

Angular anticipates that your partials should be static content (so that it can be cached), and your logic controlling what should be displayed should be in a controller.

You should re-structure your code so that a GET request to /broadcast/* always returns the same HTML regardless of the content of your session.

However, if /broadcast/* is NOT supposed to return a partial, then perhaps you need to make a change to the <a> tag in whichever page links to it, adding target="_top". This will ensure that ngRouter won't hijack the click (appending the hash). e.g. <a href="/broadcast/123" target="_top">Link</a>

I can't offer any more help without seeing the rest of your client side scripts.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top