I've written authentication part of my app long ago (there are a few jquery ajax calls), now I moved away from jQuery to Angular, so I won't be using Express.js for routing anymore.I used to match "/" (localhost) like that.router.get('/', csrfProtection, indexOnly, indexController.index); I'll be using ui-router, so I will only serve one index.html file and angular will handle the rest.If a user visits homepage,I check whether they're logged in or not. If they aren't, regular login page appears. If they are, they get redirected to /feed. indexOnly checks that and csrfProtection, you know, protects from csrf. I only need two of these to work on index if the user is not logged in.Here's indexController.jsexports.index = function(req, res) { res.render('frontend/index', { csrfToken: req.csrfToken() }); }; How can I do that? I tried a little but I couldn't do it.router.all('/*', function(req,res,next) { if(req.originalUrl == '/') { router.get('/', csrfProtection, indexOnly, indexController.index); } else { res.sendFile('views/index.html', { root : __dirname }); } });
Submitted January 05, 2016 at 10:37PM by laraveling
No comments:
Post a Comment