Angular and Express routing

Add these routes to your express server app.get(‘/partials/:filename’, routes.partials); app.use(routes.index); Then in routes.js exports.partials = function(req, res){ var filename = req.params.filename; if(!filename) return; // might want to change this res.render(“partials/” + filename ); }; exports.index = function(req, res){ res.render(‘index’, {message:”Hello!!!”}); }; This will make sure that express returns rendered templates when making requests to partials/index … Read more

Queries hang when using mongoose.createConnection() vs mongoose.connect()

Unfortunately, this isn’t a simple refactor. 1) .createConnection vs .connect When using .createConnection, you access models via the explicit connection you create with this call. This means that instead of User = mongoose.model(…) you need User = db.model(…). Examples (one, two, three, four) show this isn’t complicated but the change is subtle enough that many … Read more

Documentation for “ensureAuthentication” “isAuthenticated” passport’s functions?

While not explicitly documented anywhere easily found, you can see where the the isAuthenticated and isUnauthenticated flags are set in the Passport code at https://github.com/jaredhanson/passport/blob/a892b9dc54dce34b7170ad5d73d8ccfba87f4fcf/lib/passport/http/request.js#L74. ensureAuthenticated is not official, but can be implemented via the following: function ensureAuthenticated(req, res, next) { if (req.isAuthenticated()) return next(); else // Return error content: res.jsonp(…) or redirect: res.redirect(‘/login’) } … Read more

What is the difference using react-router and the express routes.js

Note: this stackoverflow post contains examples and codes that could help you a lot. It’s a classical misunderstanding. Express will handle your backend routes whereas React (with react-router or any front-end routing lib) will handle frontend routes. Your React application will probably be an SPA (single page application), meaning that your server (express or something … Read more