shawnbu
shawnbu16mo ago

Possible to have multiple http servers listening to different ports in the same module?

I'm porting a service mesh platform we wrote for NodeJS over to Deno and it is based on the idea of hosting multiple servers in the same module.
The only examples I can find for Deno's http server uses a for loop to handle requests which seems like it's blocking. Is it possible to have different http server instances listening on different ports at the same time?
3 Replies
ioB
ioB16mo ago
Yes, you can host multiple servers in one module. Are you using http? If so:
Deno.serve({ port: 1000 }, () => {
return new Response("server 1");
})
Deno.serve({ port: 2000 }, () => {
return new Response("server 2");
})
Deno.serve({ port: 3000 }, () => {
return new Response("server 3");
})
Deno.serve({ port: 1000 }, () => {
return new Response("server 1");
})
Deno.serve({ port: 2000 }, () => {
return new Response("server 2");
})
Deno.serve({ port: 3000 }, () => {
return new Response("server 3");
})
shawnbu
shawnbuOP16mo ago
Awesome, thanks The same with serveHttp also in case I need to drop in and use that instead for some reason?
ioB
ioB16mo ago
yup