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

std/http/server.ts>serve is deprecated, io.handler() is incompatible with Deno.serve #17

Open
svdvonde opened this issue Aug 2, 2023 · 3 comments
Labels
enhancement New feature or request

Comments

@svdvonde
Copy link

svdvonde commented Aug 2, 2023

Describe the bug

Deno's std/http/server.ts>serve is deprecated and will be removed in version 1.0.0. Instead they suggest to use Deno.serve.

This library currently does not seem to be compatible with Deno.serve. It throws the following error:

Deno: No overload matches this call. Overload 1 of 3, '(handler: ServeHandler): Server', gave the following error. Argument of type '(req: Request, connInfo: ConnInfo) => Response | Promise' is not assignable to parameter of type 'ServeHandler'. Overload 2 of 3, '(options: ServeInit & (ServeOptions | ServeTlsOptions)): Server', gave the following error. Argument of type '(req: Request, connInfo: ConnInfo) => Response | Promise' is not assignable to parameter of type 'ServeInit & (ServeOptions | ServeTlsOptions)'.

To Reproduce

deps.ts

export * as socketio from "https://deno.land/x/[email protected]/mod.ts";

test.ts

import { socketio } from "./deps.ts";
const io = new socketio.Server();
Deno.serve(io.handler());

Expected behavior

Ideally I would expect the socketio handler to be compatible with Deno.serve.

Platform:

MacOS 13.5 (Intel-based)
deno 1.35.3 (release, x86_64-apple-darwin)
v8 11.6.189.12
typescript 5.1.6

@darrachequesne
Copy link
Member

Hi! I was indeed able to reproduce, thanks for reporting the issue 👍

@darrachequesne darrachequesne added the enhancement New feature or request label Aug 2, 2023
@TMarciDev
Copy link

TMarciDev commented Feb 19, 2024

This workaround works for me until it is being fixed

// Use io.handler() directly once it allows using parameter ServeHandlerInfo instead of ConnInfo.
const customIOHandler: Deno.ServeHandler = (
  request: Request,
  info: Deno.ServeHandlerInfo
) => {
  const localAddr: Deno.Addr = {
    transport: "tcp",
    hostname: HOSTNAME,
    port: PORT,
  };

  const connInfo: ConnInfo = {
    remoteAddr: info.remoteAddr,
    localAddr,
  };
  console.log(request)
  return io.handler()(request, connInfo);
};

Deno.serve({ port: PORT, hostname: HOSTNAME }, customIOHandler);

@olekgolus11
Copy link

Any updates on this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants