1

I am using expressjs, yeoman and angular. Yeoman has been used to setup my client side scaffolding So the structure:

root folder app --> styles --> views -->admin login.html --> scripts routes node_modules server.js

My server.js is on the root level. I am using angularjs to render but have used authentication on server side to check user.

When it uses the angularjs routes it fine on first load. If i then refresh the browser with the url it returns the error:

Express 500 Error: Failed to lookup view "/app/views/admin/users" at Function.app.render (/Users/tej/Projects/ecokidsproject/node_modules/express/lib/application.js:493:17) at ServerResponse.res.render (/Users/tej/Projects/ecokidsproject/node_modules/express/lib/response.js:798:7) at /Users/tej/Projects/ecokidsproject/server.js:148:9 at callbacks (/Users/tej/Projects/ecokidsproject/node_modules/express/lib/router/index.js:164:37) at param (/Users/tej/Projects/ecokidsproject/node_modules/express/lib/router/index.js:138:11) at pass (/Users/tej/Projects/ecokidsproject/node_modules/express/lib/router/index.js:145:5) at Router._dispatch (/Users/tej/Projects/ecokidsproject/node_modules/express/lib/router/index.js:173:5) at Object.router (/Users/tej/Projects/ecokidsproject/node_modules/express/lib/router/index.js:33:10) at Context.next (/Users/tej/Projects/ecokidsproject/node_modules/express/node_modules/connect/lib/proto.js:193:15) at Context.actions.pass (/Users/tej/Projects/ecokidsproject/node_modules/passport/lib/passport/context/http/actions.js:77:8)

config is:

     app.configure(function(){
        app.set('port', process.env.PORT || 8500);

    app.set('view engine', 'jade');
    app.use(express.static(path.join(__dirname, '../app')));
    app.use(express.static(path.join(__dirname, '/app/views')));
    app.use(express.static(path.join(__dirname, '/app/views/admin')));

    app.use(express.favicon());
    app.use(express.logger('dev'));
    app.use(express.json());
    app.use(express.urlencoded());



    // app setup for authentication
    app.use(express.bodyParser());
    app.use(express.cookieParser());
    app.use(express.session({ secret: 'ecoSecret' }));
    app.use(express.methodOverride());
    // Initialize Passport!  Also use passport.session() middleware, to support
    // persistent login sessions (recommended).
    //app.use(flash());
    app.use(passport.initialize());
    app.use(passport.session());
    app.use(app.router);

});

app.get('/admin', function(req, res){
    console.log('get admin' + __dirname + '/app/views/admin/login.html');
    res.render('/app/views/admin/users');

});
tjhack
  • 1,022
  • 3
  • 20
  • 43
  • please post your route provider configuration in your app module. – michael Jan 17 '14 at 16:34
  • i mean the angular js part. is there something in it that configures the html5 mode? – michael Jan 17 '14 at 19:36
  • yes it uses the locationprovider to set the htmlmode5 to true – tjhack Jan 17 '14 at 21:37
  • ok! if you use the html5 mode you have to make sure that your server can rewrite any url to serve your index.html, where your html5 mode is configured. please have a look at this post: http://stackoverflow.com/questions/16579404/url-rewriting-with-expressjs – michael Jan 17 '14 at 21:40
  • cheers the only reason I used html5 mode was to remove the hash appearing in the url. e.g localhost/#/admin. but take it this is the incorrect use. – tjhack Jan 17 '14 at 22:18

1 Answers1

0

I used this post and it worked a treat.

URL Rewriting with ExpressJS

Index.html needs to be rendered as this contains all include files. Therefore it will let angularjs routeprovider know what to render.

Community
  • 1
  • 1
tjhack
  • 1,022
  • 3
  • 20
  • 43