November 2013
Intermediate to advanced
148 pages
3h 12m
English
We need to create new, user-specific APIs, and we want them to use our authed() middleware. But we certainly don’t want all the other routes (like our static file serving) to be authenticated. Those still need to be served without any authentication. So we can’t just call app.use() like we would with other middleware.
When you specify a route in Express, you can include middleware that you wish to apply to only that route. We’ll use this feature for the /api/user route:
| web-app/b4/server.js | |
| | app.get('/api/user', authed, function(req, res){ |
| | res.json(req.user); |
| | }); |
This short route handler is all we need, thanks to the authed() function we already made. By the time the route handler is invoked, the middleware has ...
Read now
Unlock full access