Guest User

Untitled

a guest
Jun 20th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. export const makeGetRequest = function (token: string, options: any, cb: EVCallback) {
  2.  
  3. const req = https.get(Object.assign({}, options, {
  4. protocol: 'https:',
  5. hostname: 'registry-1.docker.io',
  6. path: '/v2/ubuntu/manifests/latest'
  7. }),
  8.  
  9. function (res) {
  10.  
  11. res.once('error', cb);
  12. res.setEncoding('utf8');
  13.  
  14. let data = '';
  15. res.on('data', function (d) {
  16. data += d;
  17. });
  18.  
  19. res.once('end', function () {
  20.  
  21. try {
  22. const r = JSON.parse(data) as any;
  23. return cb(null, r);
  24. }
  25. catch (err) {
  26. return cb(err);
  27. }
  28.  
  29. });
  30. });
  31.  
  32. req.write(`Authorization: Bearer ${token}`);
  33. req.end();
  34.  
  35. };
  36.  
  37. req.setHeader('Authorization',`Bearer ${token}`);
Add Comment
Please, Sign In to add comment