The thing is like this: I didn’t understand a section of the code that the boss lost today, and he didn’t have the shame to ask others, so he had to be shameless and ask everyone:
router.post('/my_single_article', function(req, res, next) {
var request = require('./utils/cookie-request').init(req,global.host);
request.post(global.config.api('my_single_article'),
{
form: req.body,
json:false
},
function(error, response, body){
var result = JSON.parse(body);
console.log(result+'12324');
console.log(global.host);
res.render('tpl/my_single_article_list',
{
page:result.data,
});
}
);
});
I don’t quite understand this sentence
var request = require('./utils/cookie-request').init(req,global.host);
The cookie-request block quoted is as follows:
var request = require('request');
var format = require("string-template");
exports.init = function(req, domain){
// 保持与请求接口的session一致
var url = domain || "http://album.laifuzi.cn";
var j = request.jar();
if(req && req.cookies) {
for(x in req.cookies){
var cookie = request.cookie(format('{0}={1}', x, req.cookies[x]));
j.setCookie(cookie, url);
}
}
return request.defaults({jar:j});
};
Please give me some advice from all the great gods, please
Don’t you understand this paragraph?
format('{0}={1}={2}',1,2,3)
=>1=2=3
, just formatting