#Combine multiple std http serve handlers

4 messages · Page 1 of 1 (latest)

void patio
#

Hey there,

I was wondering if it's possible to combine multiple handlers into one serve.
i.E. I'm trying to use Hono & Socket.io:

import { Hono } from 'https://deno.land/x/hono@v2.1.4/mod.ts';
import { serve } from 'https://deno.land/std@0.156.0/http/server.ts';
import { Server } from "https://deno.land/x/socket_io@0.1.0/mod.ts";

const io = new Server();

const API = new Hono();
API.route('/api', v1);

serve(API.fetch, { port: 3000 });

await serve(io.handler(), {
  port: 3000,
});```
old eagle
#

have you tried something like:

const ioHandler = io.handler();
await serve((req) => Promise.all([API.fetch(req), ioHandler(req)]), { port: 3000 });
#

though make sure only one of those handler responds to a request

#

so might wanna run only one of those handlers on a condition such as based on request path instead of just Promise.all'ing both