當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript connect-mongo類代碼示例

本文整理匯總了TypeScript中connect-mongo的典型用法代碼示例。如果您正苦於以下問題:TypeScript connect-mongo類的具體用法?TypeScript connect-mongo怎麽用?TypeScript connect-mongo使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了connect-mongo類的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: MongoStore

import * as fs from 'fs';
import * as http from 'http';
import * as https from 'https';
import * as path from 'path';
import * as express from 'express';
import * as expressSession from 'express-session';
import * as mongoose from 'mongoose';
import * as MongoStore from 'connect-mongo';
const _MongoStore: MongoStore.MongoStoreFactory = MongoStore(expressSession);
import * as compression from 'compression';
import * as bodyParser from 'body-parser';
import * as cookieParser from 'cookie-parser';
import * as csrf from 'csurf';
const vhost: any = require('vhost');
const sticky: any = require('sticky-listen');

import config from './config';

import api from './api/server';
import resources from './resources-server';
import router from './router';
import streaming from './api/streaming';

// Global options
const sessionExpires: number = 1000 * 60 * 60 * 24 * 365;
const subdomainOptions = {
	base: config.publicConfig.host
};

// Init DB connection
const db: mongoose.Connection = mongoose.createConnection(config.mongo.uri, config.mongo.options);
開發者ID:sagume,項目名稱:Misskey-Web,代碼行數:31,代碼來源:server.ts

示例2: express

import * as favicon     from 'serve-favicon';
import * as helmet      from 'helmet';
import * as mongo       from 'connect-mongo';
import * as morgan      from 'morgan';
import * as passport    from 'passport';
import * as session     from 'express-session';
import { Strategy }     from 'passport-twitch';
import { resolve }      from 'app-root-path';

import api  from './routes/api';
import auth from './routes/auth';
import core from './routes/core';
import irc  from './routes/irc';

const app: express.Express = express();
const MongoStore: mongo.MongoStoreFactory = mongo(session);

app.use(compression());
app.use(helmet());
app.use(favicon(resolve('./dist/client/assets/favicon.ico')));
if (app.get('env') !== 'production') {
    app.use(morgan('dev'));
}
app.use(express.static(resolve('./dist/client'), { index: false }));
app.use(session({
    cookie: { secure: process.env.USE_TLS === 'true' },
    resave: false,
    saveUninitialized: false,
    secret: process.env.SESSION_SECRET,
    store: new MongoStore({
        touchAfter: 24 * 3600,
開發者ID:jbuerkel,項目名稱:twitchr,代碼行數:31,代碼來源:app.ts

示例3: connectMongo

import * as session from "express-session"
import * as connectMongo from "connect-mongo"

import { dbconnection } from "../models"
import AppConfig from "../config"

const MongoStore = connectMongo(session)
export const SessionMiddleware = session({
  ...AppConfig.session,
  store: new MongoStore({ mongooseConnection: dbconnection })
})
開發者ID:yanhao1991,項目名稱:shift-server,代碼行數:11,代碼來源:session.ts

示例4: express

/// <reference path="connect-mongo.d.ts" />

import * as express from 'express';
import * as mongoose from 'mongoose';
import * as session from 'express-session';
import * as connectMongo from 'connect-mongo';
import * as mongodb from 'mongodb';

var app = express();

/// Create MongoStore
var MongoStore = connectMongo(session);

/// Use MongoStore

// MongoUrlOptions
app.use(session({
    secret: 'secret',
    store: new MongoStore({url: 'mongodb://localhost/test'})
}));


app.use(session({
    secret: 'secret',
    store: new MongoStore({
        url: 'mongodb://localhost/test',
        collection: "test-sessions",
        ttl: 30 * 24 * 60 * 60 // = 30 days
    })
}));
開發者ID:0815fox,項目名稱:DefinitelyTyped,代碼行數:30,代碼來源:connect-mongo-tests.ts

示例5: connectMongo

/* Copyright (c) Microsoft Corporation. All Rights Reserved. */

import * as express from 'express';
import * as expressSession from 'express-session';
import * as passport from 'passport';
import * as mongo from 'mongodb';
import * as connectMongo from 'connect-mongo';
const MongoStore = connectMongo(expressSession);

interface User {
    provider: string,
    id: string
}

export class Authentication {
    /**
     * An Express middleware that ensures the user is authenticated.
     * If not, the user is redirected to the Solution's login page, which 
     * will authenticate against an OAuth provider and redirect back to
     * the original page after.
     */
    public ensureAuthenticated: express.RequestHandler;
    
    /**
     * Collection of objects intended only for the login page, to be
     * used for authenticating against OAuth providers.
     */
    public _loginPage: {
        users: mongo.Collection
    };
    
開發者ID:Azure,項目名稱:azure-iot-library,代碼行數:30,代碼來源:authentication.ts

示例6: MongoStore

import * as fs from 'fs';
import * as http from 'http';
import * as https from 'https';
import * as session from 'express-session';
import * as SocketIO from 'socket.io';
import * as cookie from 'cookie';
import * as mongoose from 'mongoose';
import * as MongoStore from 'connect-mongo';
const _MongoStore: MongoStore.MongoStoreFactory = MongoStore(session);
import config from '../../config';

let server: http.Server | https.Server;

if (config.https.enable) {
	server = https.createServer({
		key: fs.readFileSync(config.https.keyPath),
		cert: fs.readFileSync(config.https.certPath)
	});
} else {
	server = http.createServer();
}

const io: SocketIO.Server = SocketIO.listen(server);

// Init DB connection
const db: mongoose.Connection = mongoose.createConnection(config.mongo.uri, config.mongo.options);

const sessionStore: any = new _MongoStore({
	mongooseConnection: db
});
開發者ID:armchair-philosophy,項目名稱:Misskey-Web,代碼行數:30,代碼來源:index.ts

示例7: next

    before(async () => {
      Location = Tyr.byName.location;
      User = Tyr.byName.user;
      Subscription = Tyr.byName.tyrSubscription;
      Job = Tyr.byName.job;

      app = express();

      const MongoStore = connectMongo(session);
      const store = new MongoStore({
        url: 'mongodb://localhost:27017/tyranid_test',
        stringify: false
      });

      const COOKIE_SECRET = 'tyranid-test-secret';

      const sessionHandler = session({
        secret: COOKIE_SECRET,
        resave: false,
        rolling: true,
        saveUninitialized: true,
        store
      });

      Tyr.connect({ store });

      const user = await User.byId(1);

      app.use((req, res, next) => sessionHandler(req, res, next));

      app.use((req, res, next) => {
        if (req.session) {
          req.session.passport = { user: user!._id }; // "log in" user 1
        }

        return next();
      });

      app.use(bodyParser.json());

      Tyr.connect({
        app,
        auth: (req, res, next) => {
          (req as any).user = user; // "log in" user 1
          return next();
        }
      });

      await new Promise((resolve, reject) => {
        const http = app.listen(expressPort, () => {
          // console.log('Express listening on port ' + expressPort)
          resolve();
        });

        Tyr.connect({ http });
      });
    });
開發者ID:tyranid-org,項目名稱:tyranid,代碼行數:57,代碼來源:express.test.ts

示例8: config

  /**
   * Configure application
   *
   * @class Server
   * @method config
   * @return void
   */
  private config() {
    // connect to database
    mongoose.connect("mongodb://localhost/" + appConfig.config.database.name);

    // Use bluebird promises for mongoose
    mongoose.Promise = require("bluebird");

    //mount json form parser
    this.app.use(bodyParser.json());

    //mount query string parser
    this.app.use(bodyParser.urlencoded({ extended: true }));

    //add static paths
    this.app.use("/public", express.static(path.join(__dirname, "../client/public")));

    // catch 404 and forward to error handler
    this.app.use(function(err: any, req: express.Request, res: express.Response, next: express.NextFunction) {
      var error = new Error("Not Found");
      err.status = 404;
      next(err);
    });

    // setup session support using express session and mongodb
    this.mongoStore = connectMongo(session);

    let sessionOptions   = appConfig.config.session;
    sessionOptions.store = new this.mongoStore({ mongooseConnection: mongoose.connection });

    if (this.app.get("env") === "production") {
        this.app.set("trust proxy", 1); // trust first proxy
        sessionOptions.cookie.secure = true; // serve secure cookies
    }

    this.app.use(session(sessionOptions));
  }
開發者ID:gaudeon,項目名稱:mudJS,代碼行數:43,代碼來源:app.ts

示例9: require

 */
// import * as spdy from 'spdy'
import expressValidator = require('express-validator')

/**
 * https://github.com/Daplie/greenlock-express
 * 注意,greenlock-express 依賴 ursa/le-challenge-fs/le-store-certbot
 * spdy 的 http2 跳轉依賴 redirect-https
 */
const greenlock = require('greenlock-express')


import { routerErrorHandler, safeRouterHandler, log as appLog } from './applications'


const MongoStore = mongo(session)


/**
 * Controllers (route handlers).
 */
import * as homeController from './controllers/home'
import * as blogController from './controllers/blog'
import * as saidController from './controllers/article'

/**
 * API keys and Passport configuration.
 */
import { isMobileDevice } from './utils/device'
import { DEVICE } from './models/server/enums'
import { getAdminInfoByToken } from './services/admin-service'
開發者ID:linkFly6,項目名稱:Said,代碼行數:31,代碼來源:server.ts


注:本文中的connect-mongo類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。