app.get('/hoo/ray', (req,res,next) => {
let url = "https://www.helloworld.com/ui/fragments/header.html";
let cookie = request.cookie(req.headers["cookie"]);
let headers = {cookie};
request({url, headers}, (error, response, body) => {
url = "https://www.helloworld.com/ui/fragments/toolbox.html";
request({url, headers}, (toolboxError, toolboxResponse, toolboxBody) => {
let html = body + toolboxBody;
res.writeHead(200, {
'Content-Type' : 'text/html',
'Content-Length': html.length,
'Expires' : new Date().toUTCString()
});
res.end(html);
});
});
});
Next step, convert those callback hell to promises.
No comments:
Post a Comment