Generic webhook endpoint written in JavaScript running pre-defined scripts based on the called URLs
npm install -g captainhook
captainhook
uses a central directory containing all pre-defined script collections. Each collection you create in this directory will be executed when the corresponding endpoint is called. Thus, if you have a collection named simple-example.json
, you would trigger it by calling http://example.com:8080/simple-example
via POST
.
mkdir ~/hooks
Let’s assume the following file is called simple-example.json
. The scripts in this JSON file are executed sequentially and the output is displayed to the caller within the response body. Thus, the response always has an HTTP status code of 200
—even if a script failed.
[
"whoami",
"uptime"
]
captainhook -p 8080 -d ~/hooks
captainhook --port 8080 --dir ~/hooks
curl -X POST http://example.com:8080/simple-example
Assuming you want to deploy your application each time you push changes in Git, this simple example shows you how to solve that task and may be called from within a post-receive
hook on your Git remote or simply by using stuff like Webhooks if you’re using GitHub.
[
"cd /var/apps/example-app",
"git pull origin master",
"npm install",
"forever restartall"
]
- 0.0.1
- Initial version
- Documentation
- Tests
Copyright (c) 2015 Thomas Rasshofer
Licensed under the MIT license.
See LICENSE for more info.