@@ -21,9 +21,23 @@ _.templateSettings = {
2121 interpolate : / \{ ( .+ ?) \} / g
2222} ;
2323
24+ var shared = function ( ) {
25+ return {
26+ configure,
27+ startProfiling,
28+ stopProfiling,
29+ results,
30+ static,
31+ resourcePath
32+ } ;
33+ } ;
34+
2435// EXPORTS
2536exports . configure = configure ;
26- exports . profile = middleware ;
37+ exports . express = function ( f ) {
38+ return require ( './middlewares/express.js' ) ( f , shared ( ) ) ;
39+ } ;
40+
2741exports . for = {
2842 pg : require ( './providers/miniprofiler.pg.js' ) ,
2943 redis : require ( './providers/miniprofiler.redis.js' )
@@ -147,44 +161,6 @@ var includes = {
147161 share : _ . template ( fs . readFileSync ( path . join ( includesDir , 'share.html' ) ) . toString ( ) )
148162} ;
149163
150- function middleware ( f ) {
151- if ( ! f ) f = function ( ) { return true ; } ;
152- return function ( req , res , next ) {
153- if ( ! configured ) configure ( ) ;
154- var enabled = f ( req , res ) ;
155-
156- if ( req . path . startsWith ( resourcePath ) ) {
157- if ( ! enabled ) {
158- res . setHeader ( 'Content-Type' , 'text/plain' ) ;
159- res . writeHead ( 404 ) ;
160- res . end ( 'MiniProfiler is disabled.' ) ;
161- return ;
162- }
163-
164- var sp = req . path . split ( '/' ) ;
165- var reqPath = sp [ sp . length - 1 ] ;
166- if ( reqPath == 'results' )
167- results ( req , res ) ;
168- else
169- static ( reqPath , res ) ;
170- return ;
171- }
172- var id = startProfiling ( req , enabled ) ;
173-
174- res . locals . miniprofiler = enabled ? req . miniprofiler : {
175- include : function ( ) { return '' ; }
176- } ;
177-
178- if ( enabled ) {
179- res . on ( 'finish' , function ( ) {
180- stopProfiling ( req ) ;
181- } ) ;
182- res . setHeader ( 'X-MiniProfiler-Ids' , `["${ id } "]` ) ;
183- }
184- next ( ) ;
185- } ;
186- }
187-
188164function include ( id ) {
189165 // not profiling
190166 if ( ! id ) {
0 commit comments