本文整理汇总了TypeScript中passport.initialize函数的典型用法代码示例。如果您正苦于以下问题:TypeScript initialize函数的具体用法?TypeScript initialize怎么用?TypeScript initialize使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了initialize函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: express
return new Promise<void>((resolve, reject) => {
let app: express.Application = express();
app.set('env', 'test');
PassportInitialize();
app.use(Passport.initialize());
app.use(Passport.session());
Server.passportAuth('jwt', 'roles');
Server.setFileLimits({
fieldSize: 1024 * 1024
});
Server.loadControllers(app, ['test/data/*', '!**/*.yaml'], `${__dirname}/../..`);
Server.setParamConverter((value, type) => {
if (type.name === 'Person' && value['salary'] === 424242) {
value['salary'] = 434343;
}
return value;
});
Server.swagger(app, './test/data/swagger.yaml', 'api-docs', 'localhost:5674', ['http']);
server = app.listen(5674, (err: any) => {
if (err) {
return reject(err);
}
resolve();
});
});
示例2: require
app.configure(function(){
app.engine('html', require('ejs').renderFile);
app.set('view engine', 'html');
app.use(express.logger('dev'));
app.use(express.json());
app.use(express.urlencoded());
app.use(express.methodOverride());
app.use(express.cookieParser());
// Persist sessions with mongoStore
app.use(express.session({
secret: 'angular-fullstack secret',
/*
store: new mongoStore({
url: config.mongo.uri,
collection: 'sessions'
}, function () {
console.log("db connection open");
})
*/
}));
//use passport session
app.use(passport.initialize());
app.use(passport.session());
// Router (only error handlers should come after this)
app.use(app.router);
});
示例3: constructor
constructor() {
var session = require('cookie-session');
var flash = require('flash');
var app = express();
app.use(express.static('build/client'));
app.use('/server', express.static('server'));
app.use('/client', express.static('client'));
app.use('/bower_components', express.static('bower_components'));
app.use('/node_modules', express.static('node_modules'));
app.use(cookieParser());
app.use(session({ secret: 'victoriasecret', resave: true, saveUninitialized: true }));
app.use(passport.initialize());
app.use(passport.session());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use('/api/auth', Auth());
Database.init('test');
Passport.init();
app.listen(3000);
}
示例4: function
export default function(app) {
let env = app.get('env');
app.set('views', config.root + '/server/views');
app.set('view engine', 'jade');
app.use(compression());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(methodOverride());
app.use(cookieParser());
app.use(passport.initialize());
app.set('appPath', path.join(config.root, 'client'));
if ('production' === env) {
app.use(favicon(path.join(config.root, 'client', 'favicon.ico')));
app.use(express.static(app.get('appPath')));
app.use(morgan('dev'));
}
if ('development' === env) {
app.use(require('connect-livereload')());
}
if ('development' === env || 'test' === env) {
app.use(express.static(path.join(config.root, '.tmp')));
app.use(express.static(app.get('appPath')));
app.use(morgan('dev'));
app.use(errorHandler()); // Error handler - has to be last
}
}
示例5: 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!')
});
}
示例6: before
before((done) => {
const app = express();
passport.use(new JwtStrategy({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: JWT_SECRET
}, (payload: any, done: VerifiedCallback) => {
done(null, payload.name);
}));
app.use(passport.initialize());
app.use(passport.authenticate('jwt', { session: false }));
app.get('/', (req, res) => {
res.send('hello world! ' + req.user);
});
server = app.listen(3000, () => {
done();
});
client = axios.create({
baseURL: 'http://localhost:3000',
validateStatus: status => true
});
});
示例7: initialize
public initialize(router: express.Router): void {
router.use(passport.initialize());
const useSession = _.get(this.options, 'authOptions.session', true);
if (useSession) {
router.use(passport.session());
if (this.options.serializeUser && this.options.deserializeUser) {
passport.serializeUser((user: any, done: (a: any, b: string) => void) => {
Promise.resolve(this.options.serializeUser(user))
.then((result: string) => {
done(null, result);
}).catch((err: Error) => {
done(err, null);
});
});
passport.deserializeUser((user: string, done: (a: any, b: any) => void) => {
Promise.resolve(this.options.deserializeUser(user))
.then((result: any) => {
done(null, result);
}).catch((err: Error) => {
done(err, null);
});
});
}
}
}
示例8: 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)
}
示例9: function
module.exports = function(app) {
var env = config.env;
app.set('view engine', 'html');
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
app.use(compression());
app.use(morgan('dev'));
app.use(passport.initialize());
app.use(express.static(path.join(config.root, 'client')));
app.set('appPath', 'client');
app.use(session({
secret: config.secrets.session,
resave: true,
saveUninitialized: true,
store: new mongoStore({ mongooseConnection: mongoose.connection })
}));
if (env === 'development' || env === 'test') {
app.use(require('errorhandler')());
}
};
示例10: async
export const start = async (port: string) => {
await MongooseClient.InitMongoConnection();
const app = express();
const appRootUrl = siteName ? `https://${siteName}.azurewebsites.net` : `http://localhost:${port}`;
initPassport(appRootUrl);
enableSessions(app, SocketServer);
initSockets();
app.use(json())
app.use(passport.initialize());
app.use(passport.session());
const server = createServer(app);
SocketServer.attach(server);
app.use(Routes);
await new Promise(resolve => {
server.listen(port, () => {
console.log(`Server listening at port ${port}`);
resolve()
});
})
return async function close() {
await new Promise(resolve => server.close(resolve))
await MongooseClient.disconnect()
}
};