This repository was archived by the owner on Dec 5, 2023. It is now read-only.
  
  
  
  
    
    
    
      
    
  
  
    
File tree Expand file tree Collapse file tree 3 files changed +12
-15
lines changed Expand file tree Collapse file tree 3 files changed +12
-15
lines changed Original file line number Diff line number Diff line change 1818    return  ( diff [ 0 ]  *  1e9  +  diff [ 1 ] )  /  1000000000 ; 
1919  } 
2020
21-   function  parse ( path )  { 
22-     var  clean_path  =  path ; 
23- 
24-     if  ( path [ path . length  -  1 ]  !=  '/' )  { 
25-       if  ( ! path . includes ( '.' ) )  { 
26-         clean_path  =  path . substr ( 0 ,  path . lastIndexOf ( '/' )  +  1 ) ; 
27-       } 
28-     } ; 
29- 
30-     return  clean_path ; 
31- } 
32- 
3321  function  observe ( method ,  path ,  statusCode ,  start )  { 
3422    var  path  =  path . toLowerCase ( ) ; 
3523    if  ( path  !==  '/metrics'  &&  path  !==  '/metrics/' )  { 
3624        var  duration  =  s ( start ) ; 
3725        var  method  =  method . toLowerCase ( ) ; 
38-         var  clean_path  =  parse ( path ) ; 
39-         metric . http . requests . duration . labels ( method ,  clean_path ,  statusCode ) . observe ( duration ) ; 
26+         metric . http . requests . duration . labels ( method ,  path ,  statusCode ) . observe ( duration ) ; 
4027    } 
4128  } ; 
4229
Original file line number Diff line number Diff line change 5151    res . end ( ) ; 
5252  } 
5353
54+   /* Rewrites and redirects any url that doesn't end with a slash. */ 
55+   helpers . rewriteSlash  =  function ( req ,  res ,  next )  { 
56+    if ( req . url . substr ( - 1 )  ==  '/'  &&  req . url . length  >  1 ) 
57+        res . redirect ( 301 ,  req . url . slice ( 0 ,  - 1 ) ) ; 
58+    else 
59+        next ( ) ; 
60+   } 
61+ 
5462  /* Public: performs an HTTP GET request to the given URL 
5563   * 
5664   * url  - the URL where the external service can be reached out 
Original file line number Diff line number Diff line change @@ -15,8 +15,10 @@ var request      = require("request")
1515  ,  metrics       =  require ( "./api/metrics" ) 
1616  ,  app           =  express ( ) 
1717
18- app . use ( express . static ( "public" ) ) ; 
18+ 
19+ app . use ( helpers . rewriteSlash ) ; 
1920app . use ( metrics ) ; 
21+ app . use ( express . static ( "public" ) ) ; 
2022if ( process . env . SESSION_REDIS )  { 
2123    console . log ( 'Using the redis based session manager' ) ; 
2224    app . use ( session ( config . session_redis ) ) ; 
    
 
   
 
     
   
   
          
     
  
    
     
 
    
      
     
 
     
    You can’t perform that action at this time.
  
 
    
  
     
    
      
        
     
 
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments