Skip to content

Instantly share code, notes, and snippets.

@tjanczuk
Created September 8, 2015 23:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tjanczuk/e5dd27f26b0fe4fd86be to your computer and use it in GitHub Desktop.
Save tjanczuk/e5dd27f26b0fe4fd86be to your computer and use it in GitHub Desktop.
Get code of named webtask

Getting the source code of the named webtask

Given webtask code in getcode.js:

module.exports = function (ctx, req, res) {
    if (ctx.query.code && req.method === 'GET') {
        var token = require('jsonwebtoken').decode(ctx.token);
        return require('request').get(token.url).pipe(res);
    }
    else {
        res.end('Regular response...');
    }
}

Create a webtask:

wt create getcode.js

Call webtask without the code query parameter to perform regular action:

tj-mac:adhoc tomek$ curl https://webtask.it.auth0.com/api/run/wt-14252605067-0/getcode
Regular response...

Or call it with the code query parameter to obtain webtask code:

tj-mac:adhoc tomek$ curl https://webtask.it.auth0.com/api/run/wt-14252605067-0/getcode?code=1
module.exports = function (ctx, req, res) {
    if (ctx.query.code && req.method === 'GET') {
        var token = require('jsonwebtoken').decode(ctx.token);
        return require('request').get(token.url).pipe(res);
    }
    else {
        res.end('Regular response...');
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment