This repository has been archived by the owner. It is now read-only.
require('webtask-require')('hello')
Clone or download
ntotten Merge pull request #1 from Annyv2/master
Update readme and license
Latest commit 8821928 Apr 4, 2016
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.gitignore Updated package.json to include build script Aug 4, 2015
LICENSE Update LICENSE Jan 25, 2016
README.md Update README.md Jan 25, 2016
index.js Fix auth_token being stored in closure Aug 4, 2015
package.json Fixed .min.js not being minified Aug 7, 2015

README.md

webtask-require

Use webtask-require to call your webtasks from the browser using a require-like pattern. Run node.js code without a backend.

var wt = require('webtask-require')('<your-webtask-container>');
wt('hello').then(function(result) {
  console.log(result);
});

Install

From npm:

npm install webtask-require

Or our CDN:

<script src="http://cdn.auth0.com/js/webtask-1.0.2.min.js"></script>

Usage

If you haven't created a webtask yet, you can create one named hello by doing:

$ npm install -g wt-cli
$ wt init
$ echo "module.exports = function (cb) {cb(null, 'Hello');}" > hello.js
$ wt create hello.js

Once created, this is how you call it:

var wt = require('webtask-require')('<your-webtask-container>');
wt('hello').then(function(result) {
  console.log(result);
});

Sending parameters to the webtask

var wt = require('webtask-require')('<your-webtask-container>');
wt('hello', {foo: 'bar'}).then(function(result) {
  console.log(result);
});

Specifying an HTTP method

wt.get('hello');
wt.post('hello', { foo: 'bar' });
wt.patch('hello', { foo: 'bar' });
wr.put('hello', { foo: 'bar' });
wt.del('hello');

Calling secured webtasks

Create the webtask protected with Auth0 using JSON Web Tokens

$ echo "module.exports = function (cb) {cb(null, 'Hello');}" > hello.js
$ wt create hello.js --auth0 --clientId=<your-clientid> --clientSecret=<your-clientsecret> --auth0Domain=<yours.auth0.com>

Call it using a token obtained from Auth0

var lock = new Auth0Lock('<your-clientid>', '<yours.auth0.com>');
var wt = require('webtask-require')('<your-webtask-container>');

lock.show({
  popup: true,
}, function (err, profile, token) {
    wt.withAuth(token)('hello').then(function(result) {
        console.log(result);
    });
});

Issue Reporting

If you have found a bug or if you have a feature request, please report them at this repository issues section. Please do not report security vulnerabilities on the public GitHub issue tracker. The Responsible Disclosure Program details the procedure for disclosing security issues.

Author

Auth0

License

This project is licensed under the MIT license. See the LICENSE file for more info.