add hello world and app intro
meh not a fan of what im writing today but gotta get this thing out
This commit is contained in:
parent
c55ef32978
commit
c1ed85361b
1 changed files with 27 additions and 3 deletions
|
@ -1,8 +1,28 @@
|
||||||
# Application
|
# Application
|
||||||
|
|
||||||
A Koa application is not a 1-to-1 representation of an HTTP server,
|
A Koa application is an object containing an array of middleware generator functions
|
||||||
as one or more Koa applications may be mounted together to form larger
|
which are composed and executed in a stack-like manner upon request. Koa is similar to many
|
||||||
applications, with a single HTTP server.
|
other middleware systems that you may have encountered such as Ruby's Rack, Connect, and so on -
|
||||||
|
however a key design decision was made to provide high level "sugar" at the otherwise low-level
|
||||||
|
middleware layer. This improves interoperability, robustness, and makes writing middleware much
|
||||||
|
more enjoyable.
|
||||||
|
|
||||||
|
This includes methods for common tasks like content-negotation, cache freshness, proxy support, and redirection
|
||||||
|
among others. Despite supplying a reasonably large number of helpful methods Koa maintains a small footprint, as
|
||||||
|
no middleware are bundled.
|
||||||
|
|
||||||
|
The obligatory hello world application:
|
||||||
|
|
||||||
|
```js
|
||||||
|
var koa = require('koa');
|
||||||
|
var app = koa();
|
||||||
|
|
||||||
|
app.use(function *(){
|
||||||
|
this.body = 'Hello World';
|
||||||
|
});
|
||||||
|
|
||||||
|
app.listen(3000);
|
||||||
|
```
|
||||||
|
|
||||||
## Settings
|
## Settings
|
||||||
|
|
||||||
|
@ -18,6 +38,10 @@
|
||||||
|
|
||||||
## app.listen(...)
|
## app.listen(...)
|
||||||
|
|
||||||
|
A Koa application is not a 1-to-1 representation of an HTTP server,
|
||||||
|
as one or more Koa applications may be mounted together to form larger
|
||||||
|
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`:
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue