Act

jancurn/probe-resources-plus-webhook

  • Builds
  • latest 0.0.16 / 2017-10-08
  • Created 2017-09-13
  • Last modified 2017-10-05
  • grade 4

Description

Calls jancurn/probe-page-resources and then invokes a hard-coded webhook. The act takes same input as jancurn/probe-page-resources


API

To run the act, send a HTTP POST request to:

https://api.apify.com/v2/acts/jancurn~probe-resources-plus-webhook/runs?token=<YOUR_API_TOKEN>

The POST payload will be passed as input for the act. For more information, read the docs.


Example input

Content type: application/json

{
  "urls": [ "https://www.example.com/" ],
  "waitSecs": 1,
  "headers": {
    "User-Agent": "Something",
    "X-Test": "123"
  }
}

Source code

Based on the apify/actor-node-basic Docker image (see docs).

const _ = require('underscore');
const Apify = require('apify');
const request = require('request-promise');

Apify.main(async () => {
    const input = await Apify.getValue('INPUT');
    console.log('Calling jancurn/probe-page-resources with input:');
    console.log(JSON.stringify(input, null, 2));
    
    const run = await Apify.call('jancurn/probe-page-resources', input);
    
    // console.log(JSON.stringify(run,null,2));
    console.dir(run.output);
    for (let rec of run.output) {
         console.dir(rec); 
         
         // Test webhook, review the calls at http://mockbin.org/bin/b652e23e-5e5e-4904-8fc1-c55dcd7f6ee1/log
         if (rec.url === 'https://www.example.com/') {
             console.log('Testing webhook');
             
             const options = {
                method: 'POST',
                uri: 'http://mockbin.org/bin/b652e23e-5e5e-4904-8fc1-c55dcd7f6ee1',
                json: true,
                body: {
                    "csp-report": {
                        "blocked-uri": "https://a.postrelease.com/serve/load.js",
                        "document-uri": "https://www.perf.webmd.com/allergies/default.htm",
                        "referrer": "",
                        "violated-directive": " apifier-rpt-networkerr",
                        "effective-directive": "apifier-rpt",
                        "original-policy": "",
                        "disposition": "apifier-rpt",
                        "status-code": "404/Failed/Blocked/etc – HTTP Status Code",
                        'mime-type': 'application/x-javascript',
                        'type': 'script',
                        'method' : 'GET',
                        "script-sample": "",
                        "source-file": "https://a.postrelease.com/serve/load.js"
                    }
                }
            };
            await request(options);
         }
    }
});