npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

koa-webhook

v0.0.1

Published

koa middleware for webhooks

Downloads

12

Readme

Koa.js middleware for processing GitHub Webhooks

This library is a small middleware for Koa.js web servers that handles all the logic of receiving and verifying webhook requests from website. 为ctx增加webhook属性 方便平台判断

Example

const Koa = require('koa')
const app = new Koa()

const router = require('koa-router')()

const config = require('./config')  // 配置文件

const hook = require('./index')  // koa-webhook

// hook('token')  参数接受token值 可为字符串或者数组

router.post('/webhook',hook('mrsixcoding'), (ctx) => {
  let myhook = ctx.webhook
  console.dir(myhook)
  ctx.type = 'json'
  ctx.body = {"ok": true}
})

app
  .use(router.routes())
  .use(router.allowedMethods())

app.listen(config.port, () => {
  console.log('server start at http://localhost:' + config.port)
})

ctx.webhook 示例:

# github
{ 
  platform: 'github',
  event: 'push',
  repository: 'test-webhook1',
  errToken: true
}
# coding
{
  platform: 'codding',
  event: 'push',
  repository: 'testwebhook',
  errToken: false
}
# doding test
{ 
  platform: 'codding',
  event: 'test',
  repository: 'unknow',
  errToken: false
}
# dockerHub
{ platform: 'dockerHub',
  event: 'unknow',
  repository: 'api',
  errToken: false }

coding 配置完成后会post一段测试数据

{ zen: 'Coding! 让开发更简单', token: 'mrsixcoding' }

coding webhook header

{ 'user-agent': 'Coding.net Hook',
  'x-coding-event': 'push',
  'content-length': '1006',
  'content-type': 'application/json; charset=UTF-8',
  host: 'sunny.mrsix.top',
  connection: 'Keep-Alive',
  'accept-encoding': 'gzip,deflate' }

github 配置的 Secret 使用位于 req.header 的 "x-hub-signature" 中

github webhook header

{ host: 'sunny.mrsix.top',
accept: '*/*',
'user-agent': 'GitHub-Hookshot/24a53fc',
'x-github-event': 'push',
'x-github-delivery': '732c5c80-7cc8-11e7-9b13-16d831c4e638',
'content-type': 'application/json',
'x-hub-signature': 'sha1=6f558b1e8211e03430262320d1a74b3d4a113c2e',
'content-length': '6913' }

docker hub webhook header (无token配置)

{ host: 'sunny.mrsix.top',
  connection: 'keep-alive',
  'accept-encoding': 'gzip, deflate',
  accept: '*/*',
  'user-agent': 'python-requests/2.11.1',
  'content-type': 'application/json',
  'content-length': '11078',
  'x-newrelic-id': 'UQUFVFJUGwUJVlhaBgY=',
  'x-newrelic-transaction': 'PxRTBFMHXlYEVlJXUQkCBFdVFB8EBw8RVU4aBl0NUFRWUQtSBAcLVwYFU0NKQV1SVVwHAAECFTs=' }