• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

TypeScript connect-mongo类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了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;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
TypeScript connect-redis类代码示例发布时间:2022-05-28
下一篇:
TypeScript connect-livereload类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap