当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript express-session.default方法代码示例

本文整理汇总了TypeScript中express-session.default方法的典型用法代码示例。如果您正苦于以下问题:TypeScript express-session.default方法的具体用法?TypeScript express-session.default怎么用?TypeScript express-session.default使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在express-session的用法示例。


在下文中一共展示了express-session.default方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: server

export default function server(session: any): express.Express {

	// Init server
	const app: express.Express = express();
	app.disable('x-powered-by');

	app.use(bodyParser.urlencoded({ extended: true }));
	app.use(cookieParser(config.cookiePass));

	// Session settings
	app.use(expressSession(session));

	// CSRF
	app.use(csrf({
		cookie: false
	}));

	// CORS
	app.use(cors({
		origin: true,
		credentials: true
	}));

	app.use((req, res, next) => {
		res.header('X-Frame-Options', 'DENY');
		next();
	});

	router(app);

	return app;
}
开发者ID:armchair-philosophy,项目名称:Misskey-Web,代码行数:32,代码来源:server.ts

示例2: function

export default function(cthulhu: Application, secret: string) {
  if (secret === void 0) { throw Error("Must provide `secret` in configuration"); }

  cthulhu.use(session({
    genid(req) {
      return uuid.v4();
    },
    // Do not save session if nothing has been modified
    resave: false,
    // Do not create session unless something is to be stored
    saveUninitialized: false,
    secret,
  }));
}
开发者ID:charlesponti,项目名称:cthulhu,代码行数:14,代码来源:session.ts

示例3: default

export default (app: any) =>
{
  app
    .set('views', __dirname + '/../../views')
    .set('view engine', 'jade')
  app
    .use(compress())
    .use(express.static(__dirname + '/../../../public'))
    .use(bodyParser.json())
    .use(bodyParser.urlencoded({extended: true}))
    .use(session({secret: 'keyboard cat', resave: true, saveUninitialized: true}))
    .use(passport.initialize())
    .use(passport.session())
    .use(morgan('dev'))
}
开发者ID:aberenyi,项目名称:mean-boilerplate-ts,代码行数:15,代码来源:configExpress.ts

示例4: function

db.once('open', function () {
    console.log("Get passport...")
    let passport = require("./passport");
    console.log("Add middleware...");
    let app = express();
    if (process.env.NODE_ENV === 'production') {
        require('express-http2-workaround')({ express: express, http2: http2, app: app });///Fix http2 and express compatibility.
    }
    let st = [__dirname, ...config.staticLocation]
    if (process.env.NODE_ENV === 'production') {
        app.use(express.static(path.join(...st)));
    }
    let sessionOpts = {
        saveUninitialized: true, // saved new sessions
        resave: false, // do not automatically write to the session store
        store: new MongoStore({ mongooseConnection: mongoose.connection }),
        secret: config.db.secret,
        cookie: { httpOnly: true, maxAge: 2419200000 } // configure when sessions expires
    }
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded({ extended: true }))
    app.use(cookieParser(config.db.secret))
    app.use(flash())//This is how we setup flash fail authentication.
    app.use(session(sessionOpts));
    app.use(passport.initialize());///Attach passport to express middleware.
    app.use(passport.session());
    if (config.jsTogz) {
        app.get('*.js', function (req, res, next) {
            req.url = req.url + '.gz';
            res.set('Content-Encoding', 'gzip');
            next();
        });
    }
    console.log("Add routes...");
    require('./routes/index')(app, passport);
    console.log("");
    let options = {
        key: fs.readFileSync(config.ssl.key),
        cert: fs.readFileSync(config.ssl.cert)
    };
    if (process.env.NODE_ENV === 'production') {
        http2.createServer(options, app).listen(config.port, (error) => {
            if (error) {
                console.error(error)
                return process.exit(1)
            } else {
                console.log('Listening on port: ' + config.port + '.')
            }
        });
    } else {
        http.createServer(app).listen(config.port, (error) => {
            if (error) {
                console.error(error)
                return process.exit(1)
            } else {
                console.log('Listening on port: ' + config.port + '.')
            }
        });
    }
});
开发者ID:mortonprod,项目名称:CleaningWebsite,代码行数:60,代码来源:index.ts

示例5: main

async function main() {
  const app = express();
  app.use(cors());

  await initAccounts();

  app.use(session({
    secret: 'grant',
    resave: true,
    saveUninitialized: true,
  }));

  app.use(bodyParser.urlencoded({ extended: true }));

  const grant = new Grant(grantConfig);

  app.use(GRANT_PATH, grant);

  app.get(`${GRANT_PATH}/handle_facebook_callback`, function (req, res) {
    const accessToken = req.query.access_token;
    res.redirect(`${STATIC_SERVER}/login?service=facebook&access_token=${accessToken}`);
  });

  app.get(`${GRANT_PATH}/handle_google_callback`, function (req, res) {
    const accessToken = req.query.access_token;
    res.redirect(`${STATIC_SERVER}/login?service=google&access_token=${accessToken}`);
  });

  initializeOAuthResolver();

  const schema = createSchemeWithAccounts(AccountsServer);

  app.use('/graphql', bodyParser.json(), graphqlExpress(request => ({
    schema,
    context: JSAccountsContext(request),
    debug: true,
  })));

  app.use('/graphiql', graphiqlExpress({
    endpointURL: '/graphql',
  }));

  const server = createServer(app);

  new SubscriptionServer(
    {
      schema,
      execute,
      subscribe,
    },
    {
      path: WS_GQL_PATH,
      server,
    }
  );

  server.listen(PORT, () => {
    console.log('Mock server running on: ' + PORT);
  });
}
开发者ID:RocketChat,项目名称:Rocket.Chat.PWA,代码行数:60,代码来源:index.ts

示例6: startServer

function startServer(callback) {
    const fileStore = sessionFileStore(expressSession);

    let app = express();
    app.use(cookieParser());
    app.use(bodyParser.urlencoded({extended: true}));
    app.use(expressSession({
        store: new fileStore(),
        secret: 'alarm-clock',
        resave: false,
        saveUninitialized: true,
        cookie: {
            expires: new Date(253402300000000) // Approximately Fri, 31 Dec 9999 23:59:59 GMT
        }
    }));
    app.use(passport.initialize());

    routes(app);
    app.use(express.static(path.join(__dirname, '../../web/static')));
    app.use(express.static(path.join(__dirname, '../../build-web')));
    app.use(function (req: express.Request, res: express.Response, next: express.NextFunction) {
        console.log('Invalid path: ' + req.originalUrl);
        next();
    });
    app.listen(PORT, callback)
}
开发者ID:joeferner,项目名称:alarm-clock,代码行数:26,代码来源:index.ts

示例7: start

  start() {
    let app: express.Express = express();
    app.use('/', express.static('public'));
    var upload: multer.Instance = multer(); // for parsing multipart/form-data

    //Server Middlewares configuration part
    app.use(allowCrossDomain);
    app.use(cookieParser()); // read cookies (needed for auth)
    app.use(bodyParser.json()); // for parsing application/json
    app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
    app.use(expressSession({secret: 'swcmi'}));

    

    //To use passport 
    app.use(passport.initialize());
    app.use(passport.session()); // persistent login sessions

    //start router
    this.apiRouter.init(app);


    //port
    app.listen(10000, function () {
      console.log('SuWon church API Server listening on port 10000!')
    });

  }
开发者ID:jcdby,项目名称:SuwonCMIAPIServer,代码行数:28,代码来源:server.ts

示例8: bootstrap

async function bootstrap() {
    const app = await NestFactory.create(AppModule);

    app.use(
        session({

            secret:'No sera de tomar un traguito',
            resave: false,
            saveUninitialized: true,
            cookie: {secure: false},
            name: 'server-session-id',
            store: new FileStore()
        })
    );
    app.use(cookieParser(
        'me gustan los tacos', // secreto
        {  // opciones

        }
    ));
    app.set('view engine', 'ejs');
    app.use(
        express.static('publico')
    );

    await app.listen(3000);
}
开发者ID:2018-B-GR1-AplicacionesWeb,项目名称:huertas-cuastumal-jimmy-andres,代码行数:27,代码来源:main.ts

示例9: 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

示例10: setup

	public setup() {
		this.logger.debug("Enabling session....");
        this.app.use(expressSession({
            cookie: { maxAge: 3600000 * 12 },
            resave: false,
            saveUninitialized: true,
            secret: credentials.Session.secretPhrase,
            unset: "destroy",
        }));
		this.logger.debug("Session configured.");
	}
开发者ID:Event-Starter-Kit,项目名称:website,代码行数:11,代码来源:006.session.ts


注:本文中的express-session.default方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。