node-webhooks

授权协议 Readme
开发语言 JavaScript
所属分类 Web应用开发、 常用JavaScript包
软件类型 开源软件
地区 不详
投 递 者 勾喜
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

node-webhooks

What WebHooks are used for

Webhooks are "user-defined HTTP callbacks". They are usually triggered by some event, such as pushing code to a repository or a comment being posted to a blog. When that event occurs, the source site makes an HTTP request to the URI configured for the webhook. Users can configure them to cause events on one site to invoke behaviour on another. The action taken may be anything. Common uses are to trigger builds with continuous integration systems or to notify bug tracking systems. Since they use HTTP, they can be integrated into web services without adding new infrastructure.

Install

npm install node-webhooks --save

Supporting Node.js 0.12 or above.

How it works

When a webHook is triggered it will send an HTTPS POST request to the attached URLs, containing a JSON-serialized Update (the one specified when you call the trigger method).

Debug

This module makes use of the popular debug package. Use the env variable to enable debug: DEBUG=node-webhooks.To launch the example and enable debug: DEBUG=node-webhooks node example.js

Usage

// Initialize WebHooks module.
var WebHooks = require('node-webhooks')

// Initialize webhooks module from on-disk database
var webHooks = new WebHooks({
    db: './webHooksDB.json', // json file that store webhook URLs
    httpSuccessCodes: [200, 201, 202, 203, 204], //optional success http status codes
})

// Alternatively, initialize webhooks module with object; changes will only be
// made in-memory
webHooks = new WebHooks({
    db: {"addPost": ["http://localhost:9100/posts"]}, // just an example
})

// sync instantation - add a new webhook called 'shortname1'
webHooks.add('shortname1', 'http://127.0.0.1:9000/prova/other_url').then(function(){
	// done
}).catch(function(err){
	console.log(err)
})

// add another webHook
webHooks.add('shortname2', 'http://127.0.0.1:9000/prova2/').then(function(){
	// done
}).catch(function(err){
	console.log(err)
});

// remove a single url attached to the given shortname
// webHooks.remove('shortname3', 'http://127.0.0.1:9000/query/').catch(function(err){console.error(err);})

// if no url is provided, remove all the urls attached to the given shortname
// webHooks.remove('shortname3').catch(function(err){console.error(err);})

// trigger a specific webHook
webHooks.trigger('shortname1', {data: 123})
webHooks.trigger('shortname2', {data: 123456}, {header: 'header'}) // payload will be sent as POST request with JSON body (Content-Type: application/json) and custom header

Available events

We're using an event emitter library to expose request information on webHook trigger.

var webHooks = new WebHooks({
    db: WEBHOOKS_DB,
    DEBUG: true
})

var emitter = webHooks.getEmitter()

emitter.on('*.success', function (shortname, statusCode, body) {
    console.log('Success on trigger webHook' + shortname + 'with status code', statusCode, 'and body', body)
})

emitter.on('*.failure', function (shortname, statusCode, body) {
    console.error('Error on trigger webHook' + shortname + 'with status code', statusCode, 'and body', body)
})

This makes possible checking if a webHook trigger was successful or not getting request information such as status code or response body.

The format for the events is built as eventName.result. The choosen library eventemitter2 provides a lot of freedom for listening events. For example:

  • eventName.success
  • eventName.failure
  • eventName.*
  • *.success
  • *.*

API examples

webHooks are useful whenever you need to make sure that an external service get updates from your app.You can easily develop in your APP this kind of webHooks entry-points.

  • GET /api/webhook/getReturn the whole webHook DB file.

  • GET /api/webhook/get/[WebHookShortname]Return the selected WebHook.

  • POST /api/webhook/add/[WebHookShortname]Add a new URL for the selected webHook. Requires JSON params:

  • GET /api/webhook/delete/[WebHookShortname]Remove all the urls attached to the selected webHook.

  • POST /api/webhook/delete/[WebHookShortname]Remove only one single url attached to the selected webHook.A json body with the url parameter is required: { "url": "http://..." }

  • POST /api/webhook/trigger/[WebHookShortname]Trigger a webHook. It requires a JSON body that will be turned over to the webHook URLs. You can also provide custom headers.

Author

Rocco Musolino - @roccomuso

  • 一、安装所需的软件 二、进行具体配置 三、使用 以下配置及安装为已运行实测的笔记整理,严格按照该步骤进行配置,大概率上不会有问题。不懂linux的小白也可配置使用。当然,最好还是了解一些linux基本的命令和文件的作用,可能会更好一些。欢迎评论区交流!!! 配置centos镜像源整理 1、先将原文件备份 mv /etc/yum.repos.d/CentOS-Base.repo /etc/yum.r

  • WebHooks自动化部署 一直想研究自动化部署的,因为每次都要手动拖拽发版特别麻烦,还要不停的被测试催着发版,脑壳疼,每次做这种重复机械的活懒癌就生出来了,不想动。docker部署就不说了,都是很简单的活,然后第一次的时候需要手动git clone一下,然后npm install。因为这些都是可以第一次手动来做,不需要多次重复执行的,只让脚本走多次重复执行的步骤。 服务器上的目录也不细说了。 没

  • k8s部署node express web应用 本文档用于梳理k8s部署node应用的过程 关于k8s的部署步骤可以参考:《k8s部署,亲测有效,无坑》 准备项目 项目名称 开放端口 路由1 路由2 websvr1 3000 /web1/index /web1/send websvr2 3001 /web2/index /web2/send 为了快速搭建,此处的websvr采用express的脚手

  • node .js 同步 Node.js中的iOS订阅自动续订和取消 (Automatic iOS Subscription renewal and cancellation in Node.js) Managing subscriptions for iOS apps is critical infrastructure to ensure users have access to the cor

  • 今天研究并实现一个响应 GitHub Webhooks 实现自动部署的 Web 服务。简单收拾了下代码和文档,开源至此 前提条件 这并不是一个 Hello Word 教学示例,而是我自己在用的实际项目。假设你已经知道下列技术或满足其条件: 有一台自己的服务器 会配置域名 会配置 nginx 或者其他 Web 服务器,实现 Web 服务至 node 服务的转发 了解 node、koa 了解 Webh

 相关资料
  • Node是kubernetes集群的工作节点,可以是物理机也可以是虚拟机。 Node的状态 Node包括如下状态信息: Address HostName:可以被kubelet中的--hostname-override参数替代。 ExternalIP:可以被集群外部路由到的IP地址。 InternalIP:集群内部使用的IP,集群外部无法访问。 Condition OutOfDisk:磁盘空间不足时

  • node 负责 peer node 子命令。

  • 这用于确定进程需要运行的节点的值。 由于分布式编程用于在不同节点上运行函数,因此在希望在不同机器上运行程序时,此功能非常有用。 语法 (Syntax) node() 参数 (Parameters) None 返回值 (Return Value) 这将返回本地节点的名称。 如果节点未分发,则返回nonode@nohost 。 例如 (For example) -module(helloworld)

  • The Po.et Node The Po.et Node allows you to timestamp documents in a decentralized manner. It's built on top of the Bitcoin blockchain and IPFS. Index The Po.et Node Index How to Run the Po.et Node De

  • Node-Lua是一款基于Lua实现的脚本和服务器引擎,它支持构建海量Lua服务(Context_Lua)并以多线程方式运行在多核服务器上,采用了任务多路复用的设计方案,有效利用了多核优势。node-lua致力于构建一个快速、简单易用的Lua脚本和服务器开发和运行环境。该引擎参考了Node-Js和Skynet的设计思想,并对其进行了整合和优化。 该引擎当前版本实现了以下特性: 引擎核心层同时支持同

  • 在程序里经常都需要生成一些特定格式的 id ,每种场合的需求都可能有些不一样,虽然写起来代码不复杂,但零零碎碎的东西做多了也挺烦的,于是设计了这个用于 node.js 的万能 ID 生成器。 AnyID 生成的 ID 为字符串(也可以纯数字),信息密度尽可能的高,也就是用最少的位数表示尽量多的信息。 AnyID 设计的首要考虑原则是 API 的直观易用。看看这些例子: 指定长度,随机值填充 21