Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. export const feedMessage = functions.https.onRequest((request, response) => {
  2.     console.log('hitting entrypoint directly!');
  3.         fetchFeedMessageForLine("http://www.google.com",function(resp){
  4.             response.send(resp)
  5.         });
  6. });
  7.  
  8. //internal method used to fetch Schedule info from MTA
  9. function fetchFeedMessageForLine(url:string,callback: (data:any) => void){
  10.  
  11.  
  12.     console.log('requesting: '+url);
  13.  
  14.     http.get(url, (resp:http.IncomingMessage) => {
  15.         let data = Buffer.concat([])
  16.        
  17.         // A chunk of data has been recieved.
  18.         resp.on('data', (chunk:Buffer) => {
  19.             data = Buffer.concat([data,chunk])
  20.             console.log("ondata chunking in callback!!: "+data);
  21.  
  22.         });
  23.  
  24.         // The whole response has been received. Print out the result.
  25.         resp.on('end', () => {
  26.             console.log('oh look a response!!'+ data);
  27.             callback(data);
  28.             if (resp.statusCode === 200){
  29.                 console.log("code: "+resp.statusCode + " got feedmessage for line: "+url)
  30.             } else {
  31.                 console.error("ERROR code: "+resp.statusCode + " got feedmessage for line: "+url)
  32.             }
  33.         });
  34.  
  35.     }).on("error", (err) => {
  36.       console.log("Error: " + err.message);
  37.     });
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement