Skip to content

Commit 92fd0b0

Browse files
author
haoxin
committedMar 26, 2017
update readme
1 parent ace5419 commit 92fd0b0

File tree

1 file changed

+9
-28
lines changed

1 file changed

+9
-28
lines changed
 

‎Readme.md

+9-28
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,16 @@ $ npm install koa-send
3737
For example to serve files from `./public`:
3838

3939
```js
40-
app.use(function *(){
41-
yield send(this, this.path, { root: __dirname + '/public' });
40+
app.use(async (ctx) => {
41+
await send(ctx, ctx.path, { root: __dirname + '/public' });
4242
})
4343
```
4444

4545
To serve developer specified files:
4646

4747
```js
48-
app.use(function *(){
49-
yield send(this, 'path/to/my.js');
48+
app.use(async (ctx) => {
49+
await send(ctx, 'path/to/my.js');
5050
})
5151
```
5252

@@ -61,17 +61,17 @@ You should only use the `setHeaders` option when you wish to edit the `Cache-Con
6161

6262
If you want to edit any other header, simply set them before calling `send`.
6363

64-
## Example (Koa@2) with async/await
64+
## Example
6565

6666
```js
67-
var send = require('koa-send');
68-
var Koa = require('koa');
69-
var app = new Koa();
67+
const send = require('koa-send');
68+
const Koa = require('koa');
69+
const app = new Koa();
7070

7171
// $ GET /package.json
7272
// $ GET /
7373

74-
app.use(async function (ctx, next){
74+
app.use(async (ctx) => {
7575
if ('/' == ctx.path) return ctx.body = 'Try GET /package.json';
7676
await send(ctx, ctx.path);
7777
})
@@ -80,25 +80,6 @@ app.listen(3000);
8080
console.log('listening on port 3000');
8181
```
8282

83-
## Example
84-
85-
```js
86-
var send = require('koa-send');
87-
var koa = require('koa');
88-
var app = koa();
89-
90-
// $ GET /package.json
91-
// $ GET /
92-
93-
app.use(function *(){
94-
if ('/' == this.path) return this.body = 'Try GET /package.json';
95-
yield send(this, this.path);
96-
})
97-
98-
app.listen(3000);
99-
console.log('listening on port 3000');
100-
```
101-
10283
## License
10384

10485
MIT

0 commit comments

Comments
 (0)
Please sign in to comment.