Merge remote-tracking branch 'origin/master'

pull/2/head
Sahat Yalkabov 2014-06-06 16:59:54 -04:00
commit f7b17b146f
1 changed files with 31 additions and 3 deletions

View File

@ -793,7 +793,7 @@ exports.isAuthenticated = function(req, res, next) {
```
If you are authenticated, you let this visitor pass through your "door" by calling `return next();`. It then proceeds to the
next middleware until it reaches the last argument, which is a callback function that typically renders a template on `GET` requests or redirects on `POST` requests. In this case, if you are authenticated, then you will see *Account Management* page, otherwise you will be redirected to *Login* page.
next middleware until it reaches the last argument, which is a callback function that typically renders a template on `GET` requests or redirects on `POST` requests. In this case, if you are authenticated, you will be redirected to *Account Management* page, otherwise you will be redirected to *Login* page.
```js
exports.getAccount = function(req, res) {
@ -803,7 +803,7 @@ exports.getAccount = function(req, res) {
};
```
Express.js has `app.get`, `app.post`, `app.put`, `app.del`, but for the most part you will only use the first two.
Express.js has `app.get`, `app.post`, `app.put`, `app.delete`, but for the most part you will only use the first two HTTP verbs, unless you are building a RESTful API.
If you just want to display a page, then use `GET`, if you are submitting a form, sending a file then use `POST`.
Here is a typical workflow for adding new routes to your application. Let's say we are building
@ -812,9 +812,36 @@ a page that lists all books from database.
**Step 1.** Start by defining a route.
```js
app.get('/books', bookController.getBooks);
```
---
**Note:** As of Express 4.0 you can define you routes like so:
```js
app.route('/books')
.get(bookController.getBooks)
.post(bookController.createBooks)
.put(bookController.updateBooks)
.delete(bookController.deleteBooks)
```
And here is how a route would look if it required an *authentication* and an *authorization* middleware:
```js
app.route('/api/twitter')
.all(passportConf.isAuthenticated)
.all(passportConf.isAuthorized)
.get(apiController.getTwitter);
.post(apiController.postTwitter)
```
Use whichever style that makes sense to you. Either one is acceptable. I really think that chaining HTTP verbs on
`app.route` is very clean and elegant approach, but on the other hand I can no longer see all my routes at a glance
when you have one route per line.
---
**Step 2.** Create a new controller file called `book.js`.
```js
/**
@ -1145,6 +1172,7 @@ Changelog
- Added a flash message when user deletes an account
- Updated and clarified some comments
- Updated the Remove Auth message in `setup.js`
- Cleaned up `styles.less`
- Redesigned API Examples page
- Updated Last.fm API example
- Updated Steam API example