async function doMain()

in agent/agent-ngrok.js [47:100]


async function doMain(args) {
    // normal activation: make activation available to debugger
    console.log("activation");

    if (hit(args, args.$condition) && args.$ngrokUrl) {
        console.log("passing on to debugger");

        console.log("post to ngrok", args.$ngrokUrl);
        const options = {
            hostname: args.$ngrokUrl,
            port: 443,
            path: '/',
            method: 'POST',
            headers: {
                authorization: args.$ngrokAuth
            }
        };
        return new Promise((resolve, reject) => {
            const req = https.request(options, (resp) => {
                console.log("response: ", resp.statusCode);
                let body = '';

                // A chunk of data has been received.
                resp.on('data', (chunk) => {
                    body += chunk;
                });

                // The whole response has been received. Print out the result.
                resp.on('end', () => {
                    resolve(JSON.parse(body));
                });

            });
            req.on("error", err => {
                console.error(err);
                reject(err);
            });
            args.$activationId = process.env.__OW_ACTIVATION_ID;
            delete args.$ngrokUrl;
            delete args.$ngrokAuth;
            req.write(JSON.stringify(args));
            req.end();
        });

    } else {
        console.log("condition evaluated to false (or $ngrokUrl missing), executing original action");
        return openwhisk().actions.invoke({
            name: `${process.env.__OW_ACTION_NAME}_wskdebug_original`,
            params: args,
            blocking: true,
            result: true
        });
    }
}