Skip to content
This repository was archived by the owner on Oct 13, 2025. It is now read-only.

Commit 2f56475

Browse files
committed
Merge branch 'jamesvillarrubia-master'
2 parents 9631700 + 742ca26 commit 2f56475

File tree

5 files changed

+43
-30
lines changed

5 files changed

+43
-30
lines changed

lib/library.js

Lines changed: 20 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/library.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/library.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/library.min.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/routes/cache.js

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,33 +5,35 @@ import RedisCache from './helpers/redis';
55
const HTTP_OK = 200;
66
const HTTP_NO_CONTENT = 204;
77
const HTTP_SERVER_ERROR = 500;
8+
const HTTP_NOT_FOUND = 404;
89

910
function routes(app) {
1011
const router = express.Router();
1112
const client = app.get('redisClient');
1213
const h = new RedisCache(client);
1314

1415
router.get('/clear', (req, res) => {
15-
client.flushall();
16-
res.status(HTTP_OK).json({
17-
message: 'Cache cleared',
18-
status: HTTP_OK
16+
client.flushall('ASYNC', () => {
17+
res.status(HTTP_OK).json({
18+
message: 'Cache cleared',
19+
status: HTTP_OK
20+
});
1921
});
20-
});
22+
}); // clear a unique route
2123

2224
// clear a unique route
23-
router.get('/clear/single/:target', (req, res) => {
24-
let target = decodeURIComponent(req.params.target);
25+
router.get('/clear/single/*', (req, res) => {
26+
let target = decodeURIComponent(req.params[0]);
2527
// Formated options following ?
2628
const query = req.query;
2729
const hasQueryString = (query && (Object.keys(query).length !== 0));
2830

2931
// Target should always be defined as Express router raises 404
3032
// as route is not handled
31-
if (target) {
33+
if (target.length) {
3234
if (hasQueryString) {
3335
// Keep queries in a single string with the taget
34-
target = decodeURIComponent(req.url.split('/')[3]);
36+
target = decodeURIComponent(req.url.split('/').slice(3).join('/'));
3537
}
3638

3739
// Gets the value of a key in the redis client
@@ -66,16 +68,18 @@ function routes(app) {
6668

6769
}
6870
});
71+
} else {
72+
res.status(HTTP_NOT_FOUND).end();
6973
}
7074
});
7175

7276
// clear a group
73-
router.get('/clear/group/:target', (req, res) => {
74-
let target = decodeURIComponent(req.params.target);
77+
router.get('/clear/group/*', (req, res) => {
78+
let target = decodeURIComponent(req.params[0]);
7579

7680
// Target should always be defined as Express router raises 404
7781
// as route is not handled
78-
if (target) {
82+
if (target.length) {
7983
target = 'group-' + target;
8084
// Returns elements of the list associated to the target/key 0 being the
8185
// first and -1 specifying get all till the latest
@@ -91,7 +95,7 @@ function routes(app) {
9195
h.clearGroup(target).then(r => {
9296
res.status(HTTP_OK).json({
9397
message:
94-
`cache cleared for the group key: ${decodeURIComponent(req.params.target)}`,
98+
`cache cleared for the group key: ${decodeURIComponent(req.params[0])}`,
9599
status: HTTP_OK
96100
});
97101
});
@@ -103,12 +107,14 @@ function routes(app) {
103107
*/
104108
res.status(HTTP_OK).json({
105109
message:
106-
`cache already cleared for the group key: ${decodeURIComponent(req.params.target)}`,
110+
`cache already cleared for the group key: ${decodeURIComponent(req.params[0])}`,
107111
status: HTTP_NO_CONTENT
108112
});
109113
}
110114
}
111115
});
116+
} else {
117+
res.status(HTTP_NOT_FOUND).end();
112118
}
113119
});
114120

0 commit comments

Comments
 (0)