File tree Expand file tree Collapse file tree 4 files changed +50
-0
lines changed
Expand file tree Collapse file tree 4 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 1+ var koa = require ( 'koa' ) ;
2+ var app = koa ( ) ;
3+ var miniprofiler = require ( '../lib/miniprofiler.js' )
4+
5+ app . use ( miniprofiler . koa ( ( ) => { return false ; } ) ) ;
6+
7+ app . use ( function * ( ) {
8+ this . body = '<html><body>hello' + this . req . miniprofiler . include ( ) + '</body></html>' ;
9+ } ) ;
10+
11+ app . listen ( 8080 ) ;
Original file line number Diff line number Diff line change 1+ module . exports = function ( f , profiler ) {
2+ if ( ! f ) f = function ( ) { return true ; } ;
3+ return function * ( next ) {
4+ profiler . configure ( ) ;
5+ var enabled = f ( this . req , this . res ) ;
6+
7+ if ( this . path . startsWith ( profiler . resourcePath ) ) {
8+ if ( ! enabled ) {
9+ this . type = 'text' ;
10+ this . status = 404 ;
11+ this . body = 'MiniProfiler is disabled' ;
12+ return ;
13+ }
14+
15+ var sp = this . path . split ( '/' ) ;
16+ var reqPath = sp [ sp . length - 1 ] ;
17+ if ( reqPath == 'results' )
18+ profiler . results ( this . req , this . res ) ;
19+ else
20+ profiler . static ( reqPath , this . res ) ;
21+ return ;
22+ }
23+ var id = profiler . startProfiling ( this . req , enabled ) ;
24+
25+ if ( enabled ) {
26+ var request = this . req
27+ this . res . on ( 'finish' , function ( ) {
28+ profiler . stopProfiling ( request ) ;
29+ } ) ;
30+ this . res . setHeader ( 'X-MiniProfiler-Ids' , `["${ id } "]` ) ;
31+ }
32+
33+ yield next ;
34+ } ;
35+ } ;
Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ exports.configure = configure;
3737exports . express = function ( f ) {
3838 return require ( './middlewares/express.js' ) ( f , shared ( ) ) ;
3939} ;
40+ exports . koa = function ( f ) {
41+ return require ( './middlewares/koa.js' ) ( f , shared ( ) ) ;
42+ } ;
4043
4144exports . for = {
4245 pg : require ( './providers/miniprofiler.pg.js' ) ,
Original file line number Diff line number Diff line change 3030 "eslint" : " ^2.10.2" ,
3131 "express" : " ^4.13.4" ,
3232 "istanbul" : " ^0.4.3" ,
33+ "koa" : " ^1.2.0" ,
3334 "mocha" : " ^2.4.5" ,
3435 "pg" : " ^4.5.5" ,
3536 "pug" : " ^2.0.0-alpha7" ,
You can’t perform that action at this time.
0 commit comments