0.0.2 • Published 7 years ago

express-webhook v0.0.2

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

express-webhook

A webhook in web development is a method of augmenting or altering the behavior of a web page, or web application, with custom callbacks. These callbacks may be maintained, modified, and managed by third-party users and developers who may not necessarily be affiliated with the originating website or application. —— wikipedia

For me, webhook can be a simple way to implement a auto deployment environment for my private site.

In my case, my private site is written in vue, and build with webpack. Every time I push my code to git server, I need to pull from my server, and it's boring enough.

Then I find the conception of webhook and I want to try it.

Usage
npm install express-webhook --save
var express = require('express');
...
var app = new express();
...

var webhook = require('express-webhook');

app.use('hooks', webhook({
    hooks: {
        '/repo1': 'echo hello!'
    }
}))
  • You need a repo on a git server which is support webhook(like GitHub, Gogs...)
  • Set the webhook event url to your path(like http://your.site/hooks/repo1), and set the event you want to hook(usually push).
  • It's good to write a shell file if you need to run complicate commands.
  • Write the command you are 'hooking' into config argument.
Config
as object or null:
  • hooks: defines hooks rules.
  • goodResultHandler: callback when command is executed properly. Default returns 200.
  • badResultHandler: callback when command is executed not properly. Default returns 400 and prints the logs.
  • notFoundHandler: callback when hook is not found. Default returns 404.
as string:

To use default config defined by others. Not prepared yet.

app.use('hooks', webhook('gogs', {...}))