Skip to content

Commit

Permalink
chore(heroku redis): integrate redis server on heroku and docker
Browse files Browse the repository at this point in the history
- add heroku redis addon on heroku
- create redis url env
- create redis config file
- test the heroku redis
- add redis image to docker-compose.yml

[maintains #168190297]
  • Loading branch information
dinorhythms committed Aug 31, 2019
1 parent 1785edf commit dd2f8bf
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .env-sample
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,5 @@ APP_EMAIL = ""
SEND_GRID_API_KEY= ""
BASE_URL = "http://localhost:3000"
SIGNIN_PAGE = ""

REDIS_URL=
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ services:
- ${DB_PORT}:${DB_PORT}
networks:
- webnet
redis:
image: redis
networks:
- webnet
backend:
build:
context: .
Expand All @@ -23,6 +27,7 @@ services:
entrypoint: ["/bin/bash", "./entrypoint.sh"]
depends_on:
- db
- redis
networks:
- webnet
networks:
Expand Down
15 changes: 15 additions & 0 deletions src/config/redis.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Redis from 'ioredis';
import './env';

const env = process.env.NODE_ENV || 'development';

const config = {
development: '',
production: process.env.REDIS_URL
};

const redisUrl = config[env];

const redis = new Redis(redisUrl);

export default redis;
3 changes: 1 addition & 2 deletions src/controllers/userController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import Redis from 'ioredis';
import { Op } from 'sequelize';
import models from '../models';
import authHelper from '../utils/authHelper';
Expand All @@ -12,6 +11,7 @@ import createTemplate from '../utils/createTemplate';
import sendMail from '../utils/sendMail';

import DbServices from '../services/dbServices';
import redis from '../config/redis';

const { User } = models;
const { getById, update, getByOptions } = DbServices;
Expand Down Expand Up @@ -81,7 +81,6 @@ const signIn = async (req, res) => {
*/

const logout = async (req, res) => {
const redis = new Redis();
const token = req.headers.authorization.split(' ')[1];

try {
Expand Down
4 changes: 1 addition & 3 deletions src/middlewares/blacklistMiddleware.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import Redis from 'ioredis';
import response from '../utils/response';
import messages from '../utils/messages';
import stripBearerToken from '../utils/stripBearerToken';

const redis = new Redis();
import redis from '../config/redis';

/**
* Token Blacklist Middleware
Expand Down

0 comments on commit dd2f8bf

Please sign in to comment.