Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do I use createNodeMiddleware in Deno #348

Open
samchouse opened this issue Sep 27, 2022 · 2 comments
Open

How do I use createNodeMiddleware in Deno #348

samchouse opened this issue Sep 27, 2022 · 2 comments
Labels
deno Status: Blocked Some technical or requirement is blocking the issue Type: Support Any questions, information, or general needs around the SDK or GitHub APIs

Comments

@samchouse
Copy link

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/[email protected]/deno/app.js:2:3458)
    at G (https://esm.sh/v95/@octokit/[email protected]/deno/app.js:2:4308)
    at Server.#respond (https://deno.land/[email protected]/http/server.ts:298:37)
    at Server.#serveHttp (https://deno.land/[email protected]/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/[email protected]/deno/webhooks-methods.js:2:256)
    at y (https://esm.sh/v95/@octokit/[email protected]/deno/webhooks-methods.js:2:195)
    at async x (https://esm.sh/v95/@octokit/[email protected]/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/[email protected]/http/server.ts:298:18)

So how would I create the server?

@wolfy1339 wolfy1339 added Type: Support Any questions, information, or general needs around the SDK or GitHub APIs deno labels Sep 27, 2022
@gr2m
Copy link
Contributor

gr2m commented Sep 27, 2022

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.

@gr2m gr2m added the Status: Blocked Some technical or requirement is blocking the issue label Sep 27, 2022
@wolfy1339
Copy link
Member

Deno has greatly improved their support for Node modules, and @octokit/webhooks has new methods that use Web crypto for browsers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deno Status: Blocked Some technical or requirement is blocking the issue Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
None yet
Development

No branches or pull requests

3 participants