@@ -5,6 +5,7 @@ import RedisCache from './helpers/redis';
55const HTTP_OK = 200 ;
66const HTTP_NO_CONTENT = 204 ;
77const HTTP_SERVER_ERROR = 500 ;
8+ const HTTP_NOT_FOUND = 404 ;
89
910function routes ( app ) {
1011 const router = express . Router ( ) ;
@@ -20,18 +21,18 @@ function routes(app) {
2021 } ) ;
2122
2223 // clear a unique route
23- router . get ( '/clear/single/:target ' , ( req , res ) => {
24- let target = decodeURIComponent ( req . params . target ) ;
24+ router . get ( '/clear/single/* ' , ( req , res ) => {
25+ let target = decodeURIComponent ( req . params [ 0 ] ) ;
2526 // Formated options following ?
2627 const query = req . query ;
2728 const hasQueryString = ( query && ( Object . keys ( query ) . length !== 0 ) ) ;
2829
2930 // Target should always be defined as Express router raises 404
3031 // as route is not handled
31- if ( target ) {
32+ if ( ! ! target ) {
3233 if ( hasQueryString ) {
3334 // Keep queries in a single string with the taget
34- target = decodeURIComponent ( req . url . split ( '/' ) [ 3 ] ) ;
35+ target = decodeURIComponent ( req . url . split ( '/' ) . slice ( 3 ) . join ( '/' ) ) ;
3536 }
3637
3738 // Gets the value of a key in the redis client
@@ -66,16 +67,18 @@ function routes(app) {
6667
6768 }
6869 } ) ;
70+ } else {
71+ res . status ( HTTP_NOT_FOUND ) . end ( )
6972 }
7073 } ) ;
7174
7275 // clear a group
73- router . get ( '/clear/group/:target ' , ( req , res ) => {
74- let target = decodeURIComponent ( req . params . target ) ;
76+ router . get ( '/clear/group/* ' , ( req , res ) => {
77+ let target = decodeURIComponent ( req . params [ 0 ] ) ;
7578
7679 // Target should always be defined as Express router raises 404
7780 // as route is not handled
78- if ( target ) {
81+ if ( ! ! target ) {
7982 target = 'group-' + target ;
8083 // Returns elements of the list associated to the target/key 0 being the
8184 // first and -1 specifying get all till the latest
@@ -91,7 +94,7 @@ function routes(app) {
9194 h . clearGroup ( target ) . then ( r => {
9295 res . status ( HTTP_OK ) . json ( {
9396 message :
94- `cache cleared for the group key: ${ decodeURIComponent ( req . params . target ) } ` ,
97+ `cache cleared for the group key: ${ decodeURIComponent ( req . params [ 0 ] ) } ` ,
9598 status : HTTP_OK
9699 } ) ;
97100 } ) ;
@@ -103,12 +106,14 @@ function routes(app) {
103106 */
104107 res . status ( HTTP_OK ) . json ( {
105108 message :
106- `cache already cleared for the group key: ${ decodeURIComponent ( req . params . target ) } ` ,
109+ `cache already cleared for the group key: ${ decodeURIComponent ( req . params [ 0 ] ) } ` ,
107110 status : HTTP_NO_CONTENT
108111 } ) ;
109112 }
110113 }
111114 } ) ;
115+ } else {
116+ res . status ( HTTP_NOT_FOUND ) . end ( )
112117 }
113118 } ) ;
114119
0 commit comments