Merge branch 'master' of github.com:koajs/koa
This commit is contained in:
commit
a58e38454f
4 changed files with 14 additions and 15 deletions
|
@ -27,8 +27,8 @@ app.listen(3000);
|
||||||
## Cascading
|
## Cascading
|
||||||
|
|
||||||
Koa middleware cascading in a more traditional way as you may be use to with similar tools -
|
Koa middleware cascading in a more traditional way as you may be use to with similar tools -
|
||||||
this was previsouly not impossible, but difficult to make user friendly due to node's callbacks,
|
this was previously very difficult to make user friendly due to node's callbacks.
|
||||||
however with generators we can achieve "true" middlware. Contrasting Connect's implementation which
|
However with generators we can achieve "true" middlware. Contrasting Connect's implementation which
|
||||||
simply passes control through series of functions until one returns, Koa yields "downstream", then
|
simply passes control through series of functions until one returns, Koa yields "downstream", then
|
||||||
control flows back "upstream".
|
control flows back "upstream".
|
||||||
|
|
||||||
|
@ -84,9 +84,9 @@ app.listen(3000);
|
||||||
|
|
||||||
## app.listen(...)
|
## app.listen(...)
|
||||||
|
|
||||||
A Koa application is not a 1-to-1 representation of an HTTP server,
|
A Koa application is not a 1-to-1 representation of a HTTP server.
|
||||||
as one or more Koa applications may be mounted together to form larger
|
One or more Koa applications may be mounted together to form larger
|
||||||
applications, with a single HTTP server.
|
applications with a single HTTP server.
|
||||||
|
|
||||||
Create and return an HTTP server, passing the given arguments to
|
Create and return an HTTP server, passing the given arguments to
|
||||||
`Server#listen()`. These arguments are documented on [nodejs.org](http://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback). The following is a useless Koa application bound to port `3000`:
|
`Server#listen()`. These arguments are documented on [nodejs.org](http://nodejs.org/api/http.html#http_server_listen_port_hostname_backlog_callback). The following is a useless Koa application bound to port `3000`:
|
||||||
|
@ -106,7 +106,7 @@ var app = koa();
|
||||||
http.createServer(app.callback()).listen(3000);
|
http.createServer(app.callback()).listen(3000);
|
||||||
```
|
```
|
||||||
|
|
||||||
This means you can spin up the same application as both HTTP and HTTPS,
|
This means you can spin up the same application as both HTTP and HTTPS
|
||||||
or on multiple addresses:
|
or on multiple addresses:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# Request
|
# Request
|
||||||
|
|
||||||
A Koa `Request` object is an abstraction on top of node's vanilla request object,
|
A Koa `Request` object is an abstraction on top of node's vanilla request object,
|
||||||
|
@ -124,7 +123,7 @@ this.body = yield db.find('something');
|
||||||
|
|
||||||
### req.secure
|
### req.secure
|
||||||
|
|
||||||
Shorthand for `this.protocol == "https"` to check if a requset was
|
Shorthand for `this.protocol == "https"` to check if a request was
|
||||||
issued via TLS.
|
issued via TLS.
|
||||||
|
|
||||||
### req.ip
|
### req.ip
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
# Response
|
# Response
|
||||||
|
|
||||||
A Koa `Response` object is an abstraction on top of node's vanilla response object,
|
A Koa `Response` object is an abstraction on top of node's vanilla response object,
|
||||||
|
@ -76,9 +75,9 @@
|
||||||
- 510 "not extended"
|
- 510 "not extended"
|
||||||
- 511 "network authentication required"
|
- 511 "network authentication required"
|
||||||
|
|
||||||
__NOTE__: don't worry too much about memorizing these strings,
|
__NOTE__: don't worry too much about memorizing these strings,
|
||||||
if you have a typo an error will be thrown, displaying this list
|
if you have a typo an error will be thrown, displaying this list
|
||||||
so you can make a correction.
|
so you can make a correction.
|
||||||
|
|
||||||
### res.length=
|
### res.length=
|
||||||
|
|
||||||
|
@ -203,8 +202,8 @@ this.redirect('/login');
|
||||||
this.redirect('http://google.com');
|
this.redirect('http://google.com');
|
||||||
```
|
```
|
||||||
|
|
||||||
To alter the default status of `302` or the response
|
To alter the default status of `302`, simply assign the status
|
||||||
body simply assign before and re-assign after this call:
|
before or after this call. To alter the body, assign it after this call:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
this.status = 301;
|
this.status = 301;
|
||||||
|
@ -243,4 +242,4 @@ this.response.lastModified = new Date();
|
||||||
|
|
||||||
```js
|
```js
|
||||||
this.response.etag = crypto.createHash('md5').update(this.body).digest('hex');
|
this.response.etag = crypto.createHash('md5').update(this.body).digest('hex');
|
||||||
```
|
```
|
||||||
|
|
|
@ -75,6 +75,7 @@ module.exports = {
|
||||||
*/
|
*/
|
||||||
|
|
||||||
error: function(msg, status){
|
error: function(msg, status){
|
||||||
|
console.warn('ctx.error is deprecated, use ctx.throw');
|
||||||
this.throw(msg, status);
|
this.throw(msg, status);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue