Multiple subdomains
How can I listen for incoming http request on multiple subdomains?
2 Replies
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:
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. 🦕Deno.serve()
listens on all subdomains. In the Request.url
property you can check the full URL the client requested:
You may want to do new URL(req.url)
so that it's easier for you to parse the URL