Github App Node Middleware rejects all requests when behind a custom path

44 views Asked by At

Using Octokit 3.1.2, this does not work:

import { createServer } from "node:http"
import { App, createNodeMiddleware } from "octokit"

const app = new App({
  ...
})

createServer(createNodeMiddleware(app.webhooks, { path: "/myapi/github/webhooks" })).listen(3001)

The middleware rejects all requests.

1

There are 1 answers

0
Aphex On

This is because the options for Middleware have changed, as per this documentation on octokit/app.js. The above code must be changed to the following to work:

createServer(createNodeMiddleware(app, { pathPrefix: "/myapi/github" })).listen(3001)

Note that both the behavior (path is now a path prefix) and the default value (/api/github/webhooks -> /api/github) have changed!

This burned over five hours of my time! I filed a bug here. https://github.com/octokit/webhooks.js/issues/946