Skip to content

Commit ff0a689

Browse files
committed
Added redis url parsing
1 parent 91f2b87 commit ff0a689

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@
3838
"koa-router": "^7.4.0",
3939
"lower-case": "^1.1.4",
4040
"mongodb": "^3.0.4",
41-
"path": "^0.12.7"
41+
"path": "^0.12.7",
42+
"redis-connection": "^5.4.0"
4243
},
4344
"devDependencies": {
4445
"eslint": "^4.18.2",

src/app.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11

22
const Koa = require('koa');
3+
const cache = require('koa-redis-cache')
34
const compress = require('koa-compress');
45
const Logger = require('koa-logger');
56
const Cors = require('@koa/cors');
67
const Helmet = require('koa-helmet');
78
const MongoClient = require('mongodb');
8-
const cache = require('koa-redis-cache');
99
const json = require('koa-json');
10+
const urlParse = require('url');
1011

1112
const home = require('./v2-routes/v2-home');
1213
const info = require('./v2-routes/v2-info');
@@ -36,10 +37,16 @@ app.use(json({ pretty: false, param: 'pretty' }));
3637

3738
// Redis cache options
3839
// 90 minute TTL
40+
const redisURL = urlParse.parse(process.env.REDISCLOUD_URL || 'redis://default:default@redis_db:6379');
41+
3942
const options = {
4043
expire: 5000,
41-
options: {
42-
url: process.env.REDISCLOUD_URL || 'redis://127.0.0.1:6379',
44+
redis: {
45+
host: redisURL.hostname,
46+
port: redisURL.port,
47+
options: {
48+
auth: redisURL.auth.split(':')[1],
49+
},
4350
},
4451
};
4552

0 commit comments

Comments
 (0)