supabase / edge-runtime

A server based on Deno runtime, capable of running JavaScript, TypeScript, and WASM services.
MIT License
642 stars 56 forks source link

TypeError: upgradeHttpRaw may only be used with Deno.serve | Connecting to websocket provided by NPM package #300

Closed colin-chadwick closed 5 months ago

colin-chadwick commented 6 months ago

Bug report

Describe the bug

When trying to connect to the websocket provided by the Hocuspocus package with the Supabase edge runtime, the following error is thrown:

[Error] TypeError: upgradeHttpRaw may only be used with Deno.serve
      at upgradeHttpRaw (ext:deno_http/00_serve.js:119:9)
      at handler (node:http:1283:36)
      at Object.handler (node:http:1301:14)
      at handleHttp (ext:sb_core_main_js/js/http.js:107:38)
      at eventLoopTick (ext:core/01_core.js:64:7)

To Reproduce

  1. The function file:
import { Server } from 'npm:@hocuspocus/server@latest'

const server = Server.configure({
  port: 8000,
})

server.listen()
  1. Try to connect to the websocket, for instance via Postman:

Bildschirmfoto 2024-03-25 um 12 04 52

  1. The socket disconnects right away and throws a 502.

Expected behavior

The socket is connecting when using the deno run command of the Deno CLI, but fails on the Supabase edge runtime, both in the hosted and in the local environment.

nyannyacha commented 6 months ago

@colin-chadwick

Yeah, this is an edge-runtime domain issue.

I was a bit worried after merging that PR earlier, so I tested the npm:ws package and it failed as expected.

Websocket upgrades via Deno.upgradeWebSocket calls within the user worker are supported, but WebSocket upgrades via the node compatibility layer were not properly implemented in the previous initial websocket support PR.

I'll review this issue and fix it soon. 😁

colin-chadwick commented 6 months ago

@nyannyacha Thanks for the quick reply. Looking forward to the fix. I think the full WS support will be a great step forward for the edge runtime. 😃

nyannyacha commented 5 months ago

Update:

https://github.com/supabase/edge-runtime/assets/46702285/62580180-9ab3-4a79-88ea-af8bd57ccfd5

https://github.com/ueberdosis/hocuspocus/blob/main/packages/server/src/Server.ts#L24-L38 https://github.com/ueberdosis/hocuspocus/blob/main/packages/server/src/Server.ts#L42-L67

github-actions[bot] commented 5 months ago

:tada: This issue has been resolved in version 1.43.0 :tada:

The release is available on GitHub release

Your semantic-release bot :package::rocket: