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

TypeScript connect-flash.default函数代码示例

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

本文整理汇总了TypeScript中connect-flash.default函数的典型用法代码示例。如果您正苦于以下问题:TypeScript default函数的具体用法?TypeScript default怎么用?TypeScript default使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



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

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


示例2: initAuth

function initAuth() {
    const flash = require('connect-flash');
    app.use(flash());

    const passport = require('passport');

    auth(passport);

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

    return passport;
}
开发者ID:yegor-sytnyk,项目名称:contoso-express,代码行数:13,代码来源:server.ts


示例3: expressConfig

function expressConfig(app) {
    app.use(compress({
        filter: function (req, res) {
            return (/json|text|javascript|css/).test(res.getHeader('Content-Type'));
        },
        level: 9
    }));

    app.set('views', path.join(__dirname, '../app/views'));
    app.set('view engine', 'jade');
    app.use(logger('dev'));
    app.use(bodyParser.json());
    app.use(bodyParser.urlencoded());
    app.use(cookieParser());
    app.use(express.static(path.join(__dirname, '../public')));

    // express/mongo session storage
    app.use(session({
        secret: 'd@s !t m@n#',
        store: new mongoStore({
            url: config.db,
            collection: 'sessions'
        })
    }));

    // use passport session
    app.use(passport.initialize());
    app.use(passport.session());

    app.use(flash());

    app.use('/', routes);

    app.use(function (req, res, next) {
        var err = new Error('Not Found');
        //err.status = 404;
        next(err);
    });

    // production error handler
    // no stacktraces leaked to user
    app.use(function (err, req, res, next) {
        res.status(err.status || 500);
        res.render('error', {
            message: err.message,
            error: {}
        });
    });
}
开发者ID:anweiss,项目名称:PlatyNEM,代码行数:49,代码来源:express.ts


示例4: initalize

  // start express application
  public initalize(app: any, config: ConfigType) {
    this.app = app;
    this.config = config;

    // view engine setup
    app.set('views', path.join(config.root, 'views'));
    app.set('view engine', 'ejs');

    // validator
    app.use(expressValidator());

    // favicon
    app.use(favicon(path.join(config.root, '.', 'public', 'favicon.ico'))); // uncomment after placing your favicon in /public

    // logger
    app.use(logger('dev'));

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

    // cookieParser
    app.use(cookieParser());

    // session
    app.use(session({
      secret: config.session.secret,
      resave: config.session.resave,
      saveUninitialized: config.session.saveUninitialized,
      cookie: { maxAge: config.session.cookie.maxAge }
    }));

    // public folder path
    const cacheTime = 10000;     // 10s
    app.use(express.static(path.join(config.root, '.', 'public'), {
      maxAge: cacheTime,
      lastModified: true,
      redirect: true }
      ));

    // Sample cache of extension match
    // app.use(function (req, res, next) {
    //     if (req.url.match(/^\/(css|js|img|font)\/.+/)) {
    //         res.setHeader('Cache-Control', 'public, max-age=3600');
    //     }
    //     next();
    // });

    // Initialize connect-flash
    app.use(flash());

    app.use(passport.initialize());
    app.use(passport.session());

    // Setup auth
    let auth = glob.sync(config.root + '/middlewares/*.+(js|ts|jsx|tsx)');
    auth.forEach(function (routes) {
      require(routes)(app);
    });

    // require(__dirname + '/middlewares/passport')(app);

    // Setup routes
    let routes = glob.sync(__dirname + '/routes/*.+(js|ts|jsx|tsx)');
      routes.forEach(function (routes) {
        require(routes)(app);
      });

    // require(__dirname + '/routes/about')(app);
    // require(__dirname + '/routes/api')(app);
    // require(__dirname + '/routes/hello')(app);
    // require(__dirname + '/routes/index')(app);
    // require(__dirname + '/routes/material')(app);
    // require(__dirname + '/routes/member')(app);
    // require(__dirname + '/routes/redux')(app);
    // require(__dirname + '/routes/simple')(app);

    // catch 404 and forward to error handler
    app.use((req: any, res: any, next: any) => {
      let err: any = new Error('Not Found');
      err.status = 404;
      next(err);
    });

    // error handlers

    // development error handler
    // will print stacktrace
    if (app.get('env') === 'development') {
      app.use((err: any, req: any, res: any, next: any) => {
        res.status(err.status || 500);
        res.render('error', {
        message: err.message,
        error: err
        });
      });
    }

    // production error handler
//.........这里部分代码省略.........
开发者ID:toannvbk93,项目名称:goemon,代码行数:101,代码来源:app-server.ts


示例5:

  app.use(compression());
  // parse application/json
  app.use(bodyParser.json());
  // parse application/x-www-form-urlencoded
  app.use(bodyParser.urlencoded({extended:false})); // get information from html forms
  // parse application/vnd.api+json as json
  //app.use(bodyParser.json({ type: 'application/vnd.api+json' }));
  // required for passport
  app.use(cookieParser()); // required before session.
  app.use(require('express-session')({
    secret: 'keyboard cat',
    resave: false,
    saveUninitialized: false
  }));
  app.use(passport.initialize());
  app.use(flash());
  app.use(passport.session());
  app.use("/", express.static('./public'));//redirect folder path
	console.log("[ = Development Express Config... = ]");
}

if ('production' == config.mode) {
  //console.log('production');
  // configure stuff here
  app.enable('trust proxy');
  //app.set('port', port);
  app.set('view engine', 'ejs'); // set up ejs for templating
  //app.use(express.static('public'), { maxAge: cachetime });
  //app.use("/js", express.static('./js'));//redirect folder path
  //app.use(favicon('./public/favicon.ico',{ maxAge: 1000 }));
  //app.use(compression());
开发者ID:Lightnet,项目名称:pcrpgow-ns,代码行数:31,代码来源:server_express.ts


示例6: done

        .then((app) => {
            app.set('view options', {pretty: false});
            app.set("etag", false);
            app.disable("x-powered-by");

            app.engine("dust", cons.dust);

            app.set("views", __dirname + "/../views");
            app.set("view engine", "dust");

            app.use(express.static(__dirname + "/../public"));

            passport.use(new LocalStrategy(
                function(username, password, done) {
                    storageManager.getAccountByEmail(username)
                        .then((account:any) => {
                            if (account === null) {
                                return done(null, false, { message: 'Incorrect account.' });
                            }
                            if (compareSync(password, account.password)) {
                                return done(null, account);
                            }
                            return done(null, false, { message: 'Incorrect password.' });
                        })
                        .catch((err:any) => {
                            console.log(err);
                            return done(null, false, { message: 'Internal error.' });
                        });
                }
            ));

            passport.serializeUser(function(account, done) {
                done(null, account.id);
            });

            passport.deserializeUser(function(id, done) {
                storageManager.getAccountById(id)
                    .then((account:any) => {
                        if (account !== undefined) {
                            return done(null, account);
                        }
                        return done(new Error("Invalid account"), null)
                    })
                    .catch((err:any) => {
                        done(err, null);
                    });
            });

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

            app.use(cookieParser());
            app.use(session({ secret: 'keyboard cat' }));
            app.use(passport.initialize());
            app.use(passport.session());

            app.use(flash());

            app.use((req:express.Request, res:express.Response, next:express.NextFunction) => {
                logger.info({method: req.method, url: req.url, protocol: req.protocol, ip: req.ip, hostname: req.hostname}, req.method + " " + req.path);
                next();
            });

            return app;
        });
开发者ID:JesseDavid,项目名称:express-typescript-sequelize,代码行数:66,代码来源:index.ts


示例7: next

    mongoStore = require('connect-mongo')({ session: session }),
    flash = require('connect-flash');

// express/mongo session storage
var expressSession = session({
        secret: 'd@s !t m@n#',
        resave: false,
        saveUninitialized: false,
        store: new mongoStore({
            url: config.db,
            collection: 'sessions'
        })
    }),
    passportInitialize = passport.initialize(),
    passportSession = passport.session(),
    flashMiddleware = flash();

var populateSession = (req: express.Request, res: express.Response, next: Function) => {
    expressSession(req, res, (err) => {
        if (_.isObject(err)) {
            return next(err);
        }

        passportInitialize(req, res, (err) => {
            if (_.isObject(err)) {
                return next(err);
            }

            passportSession(req, res, (err) => {
                if (_.isObject(err)) {
                    return next(err);
开发者ID:keepitreal,项目名称:capsize,代码行数:31,代码来源:session.ts



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


鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
TypeScript connect-history-api-fallback.default函数代码示例发布时间:2022-05-25
下一篇:
TypeScript connect.default函数代码示例发布时间:2022-05-25
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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