FjordWarden
FjordWarden10mo ago

Multiple subdomains

How can I listen for incoming http request on multiple subdomains?
2 Replies
Deno AI Helper
Deno AI Helper10mo ago
The documentation does not provide a specific example or method for listening to HTTP requests on multiple subdomains. However, it's important to note that handling multiple subdomains typically involves DNS configuration and server-side routing rather than the listening process itself. In Deno, you can listen to a specific port on a server using Deno.listen(). This function allows you to specify the port and optionally the hostname for the server. However, it does not directly handle different subdomains. Here's a basic example:
const server = Deno.listen({ port: 8080 });
const server = Deno.listen({ port: 8080 });
Once you have your server listening, you would typically use some form of routing to handle requests to different subdomains. This could be done in your request handling function by checking the host header of incoming requests. Remember, this advice is not directly from the documentation and might require additional steps depending on your specific use case and environment. 🦕
Leokuma
Leokuma9mo ago
Deno.serve() listens on all subdomains. In the Request.url property you can check the full URL the client requested:
Deno.serve(req => {
console.log(req.url) // full URL
return new Response()
});
Deno.serve(req => {
console.log(req.url) // full URL
return new Response()
});
You may want to do new URL(req.url) so that it's easier for you to parse the URL