11const WebPageTest = require ( 'webpagetest' ) ;
22const { WPT_API_KEY , COMMIT_REF , URL } = process . env ;
3- const request = require ( "request" ) ;
43
54exports . handler = function ( event , context ) {
65 const wpt = new WebPageTest ( 'https://www.webpagetest.org' , WPT_API_KEY ) ;
@@ -14,7 +13,7 @@ exports.handler = function(event, context) {
1413
1514 console . log ( 'Running WPT....' ) ;
1615
17- wpt . runTest ( URL , opts , ( err , result ) => {
16+ wpt . runTest ( URL , opts , ( err , result ) => {
1817 if ( result && result . data ) {
1918 //looking good, let's get our test URL
2019 let testURL = result . data . userUrl ;
@@ -27,17 +26,12 @@ exports.handler = function(event, context) {
2726 console . log ( "Payload...." ) ;
2827 console . log ( payload ) ;
2928
30- request . post ( { "url" : URL , "formData" : payload } , function ( err , httpResponse , body ) {
31- let msg ;
32-
33- if ( err ) {
29+ fetch ( URL , { method : "POST" , body : JSON . stringify ( payload ) } )
30+ . then ( ( response ) => console . log ( "submission succeeded" ) )
31+ . catch ( err => {
3432 msg = "Submission failed: " + err ;
3533 console . log ( msg ) ;
36- } else {
37- msg = "submission succeeded" ;
38- console . log ( msg ) ;
39- }
40- } ) ;
34+ } ) ;
4135
4236 return console . log ( 'Complete' ) ;
4337 } else {
0 commit comments