File tree 3 files changed +16
-8
lines changed
3 files changed +16
-8
lines changed Original file line number Diff line number Diff line change 20
20
21
21
function parse ( path ) {
22
22
var clean_path = path ;
23
+ var ignore_list = [ 'css' , 'img' , 'js' ] ;
23
24
24
- if ( path [ path . length - 1 ] != '/' ) {
25
- if ( ! path . includes ( '.' ) ) {
26
- clean_path = path . substr ( 0 , path . lastIndexOf ( '/' ) + 1 ) ;
27
- }
28
- } ;
25
+ if ( ignore_list . indexOf ( path . split ( '/' ) [ 1 ] ) != - 1 ) {
26
+ clean_path = '/' + path . split ( '/' ) [ 1 ] + '/' ;
27
+ }
29
28
30
29
return clean_path ;
31
30
}
35
34
if ( path !== '/metrics' && path !== '/metrics/' ) {
36
35
var duration = s ( start ) ;
37
36
var method = method . toLowerCase ( ) ;
38
- var clean_path = parse ( path ) ;
39
- metric . http . requests . duration . labels ( method , clean_path , statusCode ) . observe ( duration ) ;
37
+ metric . http . requests . duration . labels ( method , path , statusCode ) . observe ( duration ) ;
40
38
}
41
39
} ;
42
40
Original file line number Diff line number Diff line change 51
51
res . end ( ) ;
52
52
}
53
53
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
+
54
62
/* Public: performs an HTTP GET request to the given URL
55
63
*
56
64
* 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")
15
15
, metrics = require ( "./api/metrics" )
16
16
, app = express ( )
17
17
18
- app . use ( express . static ( "public" ) ) ;
18
+
19
+ app . use ( helpers . rewriteSlash ) ;
19
20
app . use ( metrics ) ;
21
+ app . use ( express . static ( "public" ) ) ;
20
22
if ( process . env . SESSION_REDIS ) {
21
23
console . log ( 'Using the redis based session manager' ) ;
22
24
app . use ( session ( config . session_redis ) ) ;
You can’t perform that action at this time.
0 commit comments