mof-cookie
Version:
cookie obtain middleware for floodesh
33 lines (26 loc) • 641 B
JavaScript
;
const request = require('request');
/*
*
*
*
*/
module.exports = (options)=>{
return function* (ctx, next){
yield new Promise((resolve) => {
request({uri:`${options.server}/cookieset/random?appName=${ctx.app.name}`, json:true}, (err, res, body)=>{
if(err){
ctx.app.logger.error(err);
}else if(!body.success){
ctx.app.logger.error(body.message);
}else{
ctx.opt.headers = ctx.opt.headers||{};
ctx.opt.headers.Cookie = body.data[0];
ctx.app.logger.debug('Use cookie: %s',ctx.opt.headers.Cookie, ctx.job.uuid);
}
resolve();
});
});
return next();
};
};