Skip to content
This repository has been archived by the owner on Apr 29, 2022. It is now read-only.

Commit

Permalink
add redis
Browse files Browse the repository at this point in the history
  • Loading branch information
sballesteros committed Nov 1, 2019
1 parent 206f647 commit 6bc0641
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 3 deletions.
1 change: 1 addition & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ jobs:
docker:
- image: circleci/node:dubnium
- image: ibmcom/cloudant-developer
- image: redis
steps:
- checkout
- restore_cache:
Expand Down
9 changes: 7 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ run:
npm install
```

### Redis

Be sure that redis is running on the default port (6379).
For convenience you can run: `npm run redis`.


### Database (CouchDB 2.x + Clouseau + Dreyfus)

Expand Down Expand Up @@ -75,7 +80,7 @@ docker logs cloudant-developer

### App

Once cloudant is running run:
Once cloudant and redis are running run:

```sh
npm run init
Expand Down Expand Up @@ -131,7 +136,7 @@ For chrome:

### Tests

Once cloudant is running run:
Once cloudant and redis are running run:

```sh
npm test
Expand Down
30 changes: 30 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"main": "index.js",
"scripts": {
"cloudant": "docker restart cloudant-developer",
"redis": "redis-server /usr/local/etc/redis.conf",
"log-cloudant": "docker logs cloudant-developer",
"extension:watch": "webpack --config webpack-extension.config.js --watch --mode development",
"extension:build": "cross-env NODE_ENV=production webpack --config webpack-extension.config.js --mode production",
Expand Down Expand Up @@ -190,6 +191,7 @@
"classnames": "^2.2.6",
"clipboard-copy": "^3.1.0",
"concat-stream": "^2.0.0",
"connect-redis": "^4.0.3",
"cors": "^2.8.5",
"date-fns": "^2.5.1",
"doi-regex": "^0.1.10",
Expand Down Expand Up @@ -217,6 +219,7 @@
"react-dropzone": "^10.1.10",
"react-icons": "^3.7.0",
"react-router-dom": "^5.1.2",
"redis": "^2.8.0",
"slug": "^1.1.0",
"uuid": "^3.3.3",
"xmldom": "^0.1.27"
Expand Down
10 changes: 9 additions & 1 deletion src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ import path from 'path';
import { STATUS_CODES } from 'http';
import express from 'express';
import session from 'express-session';
import redis from 'redis';
import connectRedis from 'connect-redis';
import authRoutes from './routes/auth-routes';
import appRoutes from './routes/app-routes';
import apiRoutes from './routes/api-routes';
import addDb from './middlewares/add-db';
import { createPassport } from './utils/orcid';
import { createRedisConfig } from './utils/redis';

export function rapid(config = {}) {
const RedisStore = connectRedis(session);

const passport = createPassport(config);

const app = express();
Expand All @@ -24,7 +29,10 @@ export function rapid(config = {}) {
secret:
config.sessionSecret || process.env.SESSION_SECRET || 'rapid-prereview',
resave: false,
saveUninitialized: false
saveUninitialized: false,
store: new RedisStore({
client: redis.createClient(createRedisConfig(config, { ns: 'sess' }))
})
})
);
app.use(passport.initialize());
Expand Down
21 changes: 21 additions & 0 deletions src/utils/redis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
export function createRedisConfig(config = {}, { ns } = {}) {
const opts = {
host: config.redisHost || process.env['REDIS_HOST'] || '127.0.0.1',
port: config.redisPort || process.env['REDIS_PORT'] || 6379
};

let redisPrefix = config.redisPrefix || 'rpos:';
if (ns) {
redisPrefix += `${ns}:`;
}

opts.prefix = redisPrefix;

const redisPassword = config.redisPassword || process.env['REDIS_PASSWORD'];
if (redisPassword) {
opts.pass = redisPassword; // for compatibility with RedisStore (used in the session middleware)
opts.password = redisPassword;
}

return opts;
}

0 comments on commit 6bc0641

Please sign in to comment.