How to use koa-generic-session - 10 common examples

To help you get started, we’ve selected a few koa-generic-session 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 zalando / zappr / server / server.js View on Github external
export function init(options = {}) {
  const passport = initPassport(options.PassportStrategy)

  return app.use(generatePrometheusMiddleware(router, {
              ignore: [/^\/repository/]
            }))
            .use(generateProblemMiddleware({
              exposableErrorTypes: [
                CHECK_ERROR_TYPE,
                GITHUB_ERROR_TYPE,
                REPO_ERROR_TYPE
              ]
            }))
            .use(morgan(morganFormat, {skip: morganSkip}))
            .use(convert(session({store: store})))
            .use(bodyParser())
            .use(passport.initialize())
            .use(passport.session())
            .use(compress())
            .use(router.routes())
            .use(router.allowedMethods())
            .use(conditional())
            .use(etag())
            .use(serve(
              nconf.get('STATIC_DIR'), {
                index: 'none',
                maxage: 1.7 * 10 ** 8 // ~ 2 days
              }))
            .use(ensureModeMiddleware)
            .use(renderStatic)
}
github rusty1s / koa2-rest-api / server / middleware / index.js View on Github external
export default function middleware() {
  return compose([
    logger(),
    helmet(), // reset HTTP headers (e.g. remove x-powered-by)
    convert(cors()),
    convert(bodyParser()),
    convert(session()),
  ]);
}
github embbnux / kails / app / index.js View on Github external
const redisStore = koaRedis({
  url: config.redisUrl
});

const app = new Koa();

app.keys = [config.secretKeyBase];

// not serve static when deploy
if(config.serveStatic){
  app.use(convert(require('koa-static')(__dirname + '/../public')));
}

app.use(convert(session({
  store: redisStore,
  prefix: 'kails:sess:',
  key: 'kails.sid'
})));

app.use(cacheMiddle());

app.use(bodyParser());
app.use(methodOverride((req, _res) => {
  if (req.body && (typeof req.body === 'object') && ('_method' in req.body)) {
    // look in urlencoded POST bodies and delete it
    const method = req.body._method;
    delete req.body._method;
    return method;
  }
}));
github lubien / koa-react-redux-universal-boilerplate / server / app.js View on Github external
import etag from 'koa-etag';
import mount from 'koa-mount';
import serve from 'koa-static';
import convert from 'koa-convert';
import session from 'koa-generic-session';
import MongoStore from 'koa-generic-session-mongo';

app.use(compress());
app.use(bodyParser());
app.use(conditional());
app.use(etag());
app.use(mount('/public', serve(path.join(__dirname, '../public'), {
  maxage: config.is.prod ? 1000 * 60 * 60 * 24 * 7 : 0,
})));
app.keys = [config.SESSIONID];
app.use(convert(session({
  store: new MongoStore({
    url: config.MONGO_URL,
  }),
})));

// Passport
import passport from './lib/passport';
import loggedInMiddleware from './lib/logged-in-middleware';
app.use(passport.initialize());
app.use(passport.session());
app.use(loggedInMiddleware());

// Views
import views from 'koa-views';
app.use(views(path.join(__dirname, 'views/'), {
  extension: 'pug',
github SystangoTechnologies / koach-sql / bin / server.js View on Github external
// }

// --------------------- start -------------------------
// Instead of calling convert for all legacy middlewares
// just use the following to convert them all at once

const _use = app.use
app.use = x => _use.call(app, convert(x))

// The code above avoids writting the following
// app.use(convert(logger()))
// ---------------------- end --------------------------
app.use(helmet())
app.use(logger())
app.use(bodyParser())
app.use(session())
app.use(errorMiddleware())

// Mount static API documents generated by api-generator
app.use(mount('/docs', serve(`${process.cwd()}/docs`)))

// Using Passport for authentication
require('../config/passport')
app.use(passport.initialize())
app.use(passport.session())

// Using module wise routing
const modules1 = require('../src/modules/v1')
const modules2 = require('../src/modules/v2')
const common = require('../src/modules/common')
modules1(app)
modules2(app)
github SystangoTechnologies / koach-javascript / bin / server.js View on Github external
// just use the following to convert them all at once

const _use = app.use
app.use = x => _use.call(app, convert(x))

// The code above avoids writting the following
// app.use(convert(logger()))
// ---------------------- end --------------------------

mongoose.Promise = global.Promise
mongoose.connect(config.database)

app.use(helmet())
app.use(logger())
app.use(bodyParser())
app.use(session())
app.use(errorMiddleware())

// Mount static API documents generated by api-generator
app.use(mount('/docs', serve(`${process.cwd()}/docs`)))

// Using Passport for authentication
require('../config/passport')
app.use(passport.initialize())
app.use(passport.session())

// Using module wise routing
const modules1 = require('../src/modules/v1')
const modules2 = require('../src/modules/v2')
const common = require('../src/modules/common')
modules1(app)
modules2(app)
github bidanjun / koa-graphql-next / src / __test__ / http-session.spec.js View on Github external
it('handles generic session for GraphQL', async () => {
      const app = new koa();
      app.keys = ['id','token'];
      app.use(convert(genericSession({
        key: 'session'
      })));

      app.use(async (ctx,next) => {
        ctx.session.id = 'first';        
        await next();
      });
    const schema = new GraphQLSchema({
        query: new GraphQLObjectType({
          name: 'SessionType',
          fields: {
            sessionId: {
              type: GraphQLString,
              resolve(parentValue, args, contextCtx) {
                  //here has session id and cookies
                  //console.log("contextCtx.session is======>",contextCtx.session)
github DefinitelyTyped / DefinitelyTyped / types / koa-generic-session / koa-generic-session-tests.ts View on Github external
import * as Koa from "koa";
import {MemoryStore, Session} from "koa-generic-session";
import session = require("koa-generic-session");

const app = new Koa();

app.use(session({
    key: 'sessionKey',
    store: MemoryStore(),
    ttl: 60 * 60,
    prefix: 'a-prefix',
    cookie: {
        path: '/test',
        rewrite: false,
        signed: false,
        maxAge: 60 * 60,
        secure: true,
        httpOnly: true,
    },
    allowEmpty: false,
    defer: false,
    reconnectTimeout: 100,
    rolling: false,
    sessionIdStore: {
        get: () => 'something',
github donniewang / koa-vue-example / app / server / index.js View on Github external
import send from 'koa-send';

import koaBody from 'koa-body';

import sqlite3 from 'co-sqlite3';

import routes from './routes';

try {
    const app = koa();
    const body = koaBody({ multipart: true,formidable:{uploadDir:path.join(__dirname, './upload')} });
    const sessionStore = require('koa-sqlite3-session');

    app.keys = ["test"];

    app.use(session({
        store: new sessionStore(path.join(__dirname, '../../db/db'), {
        })
    }));

    app.use(staticCache(path.join(__dirname, '../../public'), {
        gzip: true
    }));

    app.use(function *(next){
        var start = new Date().getTime();
        try {
            yield next;
        } catch(e) {
            console.error(e);
            this.status = 500;
        } finally {

koa-generic-session

koa generic session store by memory, redis or others

MIT
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis

Popular koa-generic-session functions