How to use connect-redis - 9 common examples

To help you get started, we’ve selected a few connect-redis examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github arturi / kotihome / koti-server / lib / express-app.js View on Github external
export default function(controller, robot) {

  let compiler = webpack(webpackConfig);

  let app = express();
  app.use(helmet());
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use('/static', express.static(path.join(__dirname, '../dist')));

  console.log(path.join(__dirname, '../dist'));

  // use session store in production only
  if (isProduction) {
    let redisStore = RedisStore(session);

    // Setup session middleware, Redis in this case
    let sessionMiddleware = session({
      cookie: { maxAge: 7 * 24 * 60 * 60 * 1000 },
      rolling: true,
      saveUninitialized: false,
      resave: true,
      store: new redisStore({
        host: 'localhost',
        port: 6379,
        db: 2
      }),
      secret: config.adminCredentials.sessionSecret
    });
    app.use(sessionMiddleware);
  }
github kriasoft / nodejs-api-starter / src / app.js View on Github external
const whitelist = process.env.CORS_ORIGIN
        ? process.env.CORS_ORIGIN.split(',')
        : [];
      cb(null, whitelist.includes(origin));
    },
    credentials: true,
  }),
);

app.use(compression());
app.use(cookieParser());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
app.use(
  session({
    store: new (connectRedis(session))({ client: redis }),
    name: 'sid',
    resave: true,
    saveUninitialized: true,
    secret: process.env.SESSION_SECRET,
  }),
);
app.use(i18nextMiddleware.handle(i18next));
app.use(passport.initialize());
app.use(passport.session());
app.use(flash());

app.use(accountRoutes);

// The following routes are intended to be used in development mode only
if (process.env.NODE_ENV !== 'production') {
  // A route for testing email templates
github argos-ci / argos / src / server / routes / www.js View on Github external
import express from 'express'
import path from 'path'
import passport from 'passport'
import configurePassport from 'server/routes/configurePassport'
import session from 'express-session'
import connectRedis from 'connect-redis'
import config from 'config'
import * as redis from 'server/services/redis'
import { apolloServer } from 'server/graphql'
import rendering from 'server/middlewares/rendering'
import errorHandler from 'server/middlewares/errorHandler'

const production = process.env.NODE_ENV === 'production'

const router = new express.Router()
const RedisStore = connectRedis(session)

// Static directory
router.use(
  '/static',
  express.static(path.join(__dirname, '../../../server/static'), {
    etag: true,
    lastModified: false,
    maxAge: '1 year',
    index: false,
  }),
)

router.use(
  session({
    secret: config.get('server.sessionSecret'),
    store: new RedisStore({ client: redis.connect() }),
github benawad / type-graphql-series / src / index.ts View on Github external
//   estimators: [
      //     // Using fieldConfigEstimator is mandatory to make it work with type-graphql
      //     fieldConfigEstimator(),
      //     // This will assign each field a complexity of 1 if no other estimator
      //     // returned a value. We can define the default value for field not explicitly annotated
      //     simpleEstimator({
      //       defaultComplexity: 1
      //     })
      //   ]
      // }) as any
    ]
  });

  const app = Express();

  const RedisStore = connectRedis(session);

  app.use(
    cors({
      credentials: true,
      origin: "http://localhost:3000"
    })
  );

  app.use(
    session({
      store: new RedisStore({
        client: redis as any
      }),
      name: "qid",
      secret: "aslkdfjoiq12312",
      resave: false,
github bookbrainz / bookbrainz-site / src / api / app.js View on Github external
app.set('trust proxy', config.site.proxyTrust);

if (app.get('env') !== 'testing') {
	app.use(logger('dev'));
}

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
	extended: false
}));
app.use(compression());


const RedisStore = redis(session);
app.use(session({
	cookie: {
		maxAge: _get(config, 'session.maxAge', 2592000000),
		secure: _get(config, 'session.secure', false)
	},
	resave: false,
	saveUninitialized: false,
	secret: config.session.secret,
	store: new RedisStore({
		host: _get(config, 'session.redis.host', 'localhost'),
		port: _get(config, 'session.redis.port', 6379)
	})
}));


// Set up routes
github alex996 / graphql-chat / src / index.js View on Github external
(async () => {
  try {
    await mongoose.connect(
      `mongodb://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOST}:${DB_PORT}/${DB_NAME}`,
      { useNewUrlParser: true }
    )

    const app = express()

    app.disable('x-powered-by')

    const RedisStore = connectRedis(session)

    const store = new RedisStore({
      host: REDIS_HOST,
      port: REDIS_PORT,
      pass: REDIS_PASSWORD
    })

    app.use(session({
      store,
      name: SESS_NAME,
      secret: SESS_SECRET,
      resave: true,
      rolling: true,
      saveUninitialized: false,
      cookie: {
        maxAge: parseInt(SESS_LIFETIME),
github metricio / metricio / app.js View on Github external
import { createServer } from 'http';
import express from 'express';
import exphbs from 'express-handlebars';
import session from 'express-session';
import connectRedis from 'connect-redis';
import socketIo from 'socket.io';

import webpackMiddleWare from './webpack.middleware';
import appMeta from './package.json';
import config from './config';
import logger from './lib/logger';
import * as storage from './lib/storage';
import startJobs from './lib/jobs';

const env = process.env.NODE_ENV || 'development';
const RedisStore = connectRedis(session);
const app = express();
const server = createServer(app);
const io = socketIo(server, {});

const sessionMiddleware = session({
  store: new RedisStore({ client: storage.client }),
  secret: config.session.secret,
  key: appMeta.name,
  cookie: { secure: env !== 'development' },
  resave: true,
  logErrors: true,
  saveUninitialized: true,
});

app.use(sessionMiddleware);
github partio-scout / reki / src / server / server.js View on Github external
async function boot(app) {
  let sessionStore = undefined;

  if ( !appConfig.isDev ) {
    app.enable('trust proxy');
    app.use(expressEnforcesSsl());
    const RedisStore = RedisStoreConstructor(session);
    sessionStore = new RedisStore({ client: redis.createClient(process.env.REDIS_URL) });
  }

  const cookieSecret = process.env.COOKIE_SECRET || getSecureRandomString();

  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: true }));
  app.use(session({
    secret: cookieSecret,
    saveUninitialized: false,
    cookie: {
      httpOnly: true,
      maxAge: 4*60*60*1000,
      secure: !appConfig.isDev,
      sameSite: 'lax',
    },
github yuchiu / Slack-Clone / server / src / middlewares / sessionConfig.js View on Github external
import connectRedis from "connect-redis";
import session from "express-session";

import redisClient from "../config/redisClient";
import {
  REDIS_PORT,
  REDIS_HOST,
  REDIS_TIME_TO_LIVE,
  SESSION_SECRET,
  SESSION_NAME
} from "../utils/secrets";

const RedisStore = connectRedis(session);

export default () =>
  session({
    store: new RedisStore({
      client: redisClient,
      port: REDIS_PORT,
      host: REDIS_HOST,
      ttl: REDIS_TIME_TO_LIVE
    }),
    secret: SESSION_SECRET,
    name: SESSION_NAME,
    resave: false,
    saveUninitialized: false,
    cookie: {
      httpOnly: false,
      path: "/",

connect-redis

Redis session store for Connect

MIT
Latest version published 3 months ago

Package Health Score

83 / 100
Full package analysis

Popular connect-redis functions