@@ -37,16 +37,16 @@ $ npm install koa-send
37
37
For example to serve files from ` ./public ` :
38
38
39
39
``` 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' });
42
42
})
43
43
```
44
44
45
45
To serve developer specified files:
46
46
47
47
``` 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' );
50
50
})
51
51
```
52
52
@@ -61,17 +61,17 @@ You should only use the `setHeaders` option when you wish to edit the `Cache-Con
61
61
62
62
If you want to edit any other header, simply set them before calling ` send ` .
63
63
64
- ## Example (Koa@2) with async/await
64
+ ## Example
65
65
66
66
``` 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 ();
70
70
71
71
// $ GET /package.json
72
72
// $ GET /
73
73
74
- app .use (async function (ctx , next ) {
74
+ app .use (async (ctx ) => {
75
75
if (' /' == ctx .path ) return ctx .body = ' Try GET /package.json' ;
76
76
await send (ctx, ctx .path );
77
77
})
@@ -80,25 +80,6 @@ app.listen(3000);
80
80
console .log (' listening on port 3000' );
81
81
```
82
82
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
-
102
83
## License
103
84
104
85
MIT
0 commit comments