Need private packages and team management tools?Check out npm Teams »

local-webhook

1.3.0 • Public • Published

local-webhook

Zero-configuration localhost webhooks. Do not use in production.

banner

Installation

yarn add -D local-webhook express

Note: express is a required peer dependency.

Usage

Setup and generate webhook as a Promise:

import LocalWebhook from 'local-webhook';
 
// Option 1: open ssh tunnel to localhost.run service (default).
await LocalWebhook.startServer({ subdomain: "sushi" });
// Option 2: use ngrok.
await LocalWebhook.startServer({ service: "ngrok", region: "eu" }); 
 
// Generate an awaitable webhook Promise.
const webhook = LocalWebhook.getPromise("wasabi");
 
// This URL can be shared with third-party services.
// Ex: https://sushi.localhost.run/wasabi
webhook.getWebhookUrl(); 
 
// Handle third-party service's webhook request once.
webhook.then(({ req, res }) => {
    res.send("Hello from promise, wasabi");
});
 
// Awaitable if necessary.
await webhook;

Generate webhook as an Observable:

// Generate a webhook Observable.
const webhook = LocalWebhook.getObservable("ichiban");
 
// This URL can be shared with third-party services.
// Ex: https://sushi.ngrok.io/ichiban
webhook.getWebhookUrl(); 
 
// Handle third-party service's webhook requests each time.
webhook.subscribe(({ req, res }) => {
  res.send("Hello from observable, ichiban");
});

To inspect and replay requests, open ngrok's web interface at localhost:4040.

Peer dependencies

Community

Let's start one together! After you ★ this project, follow me @rygu on Twitter.

Thanks

License

BSD 3-Clause license. Copyright © 2018, Rick Wong. All rights reserved.

Install

npm i local-webhook

DownloadsWeekly Downloads

0

Version

1.3.0

License

BSD-3-Clause

Unpacked Size

15.1 kB

Total Files

6

Last publish

Collaborators

  • avatar