octokit/app.js

How do I use `createNodeMiddleware` in Deno

samchouse opened this issue · 1 comments

When I try to use this function I get the following error:

TypeError: t.writeHead is not a function
    at Object.T [as onUnhandledRequest] (https://esm.sh/v95/@octokit/app@13.0.8/deno/app.js:2:3458)
    at G (https://esm.sh/v95/@octokit/app@13.0.8/deno/app.js:2:4308)
    at Server.#respond (https://deno.land/std@0.157.0/http/server.ts:298:37)
    at Server.#serveHttp (https://deno.land/std@0.157.0/http/server.ts:340:20)

I'm assuming this function is Node only so I tried to implement a basic receiver that I could use to receive events but it errors too:

await serve(async (req) => {
  const body = await req.text();

  await app.webhooks.verifyAndReceive({
    id: req.headers.get("x-github-delivery") ?? "",
    name: req.headers.get(
      "x-github-event",
    ) as EmitterWebhookEventWithStringPayloadAndSignature["name"] ?? "",
    signature: req.headers.get("x-hub-signature-256") ?? "",
    payload: body,
  });

  return new Response("ok");
}, { port: 3000 });
TypeError: Cannot read properties of null (reading 'map')
    at o (https://esm.sh/v95/@octokit/webhooks-methods@3.0.0/deno/webhooks-methods.js:2:256)
    at y (https://esm.sh/v95/@octokit/webhooks-methods@3.0.0/deno/webhooks-methods.js:2:195)
    at async x (https://esm.sh/v95/@octokit/webhooks@10.1.5/deno/webhooks.js:2:8000)
    at async Server.serve.port (file:///home/xenfo/projects/maintainer/src/index.ts:48:3)
    at async Server.#respond (https://deno.land/std@0.157.0/http/server.ts:298:18)

So how would I create the server?

gr2m commented

There are compatibility problems with Octokit + Deno, it's hard to track down. I think one problem was the crypto methods used in @octokit/webhooks, the error you see might be caused by that. Your code to build a custom middleware does look correct to me.

We are working towards a native ESM Octokit at https://github.com/octokit/octokit-next.js, compatibility with Deno and other JS runtime environments is a big reason why we do that. But webhooks are not implemented yet, I'm afraid.