Reputation: 1423
This question has already been asked here, but I am not sure enough detail was given to provide an answer.
I would like to implement custom routing that allows me to be able to match a route segment depending on the subdomain of the URL.
For example, I would like to be able to do something similar to this:
// This route should match where the URL is
// www.mysite.com
Get["/"] = _ => return "Home";
// This route should match where the URL is
// {anything else}.mysite.com
Get["/:subdomain"] = _ => return "Subdomain home";
I would like the :subdomain
route to be a 'catch-all' for any requests that come in with a URL that is not www.mysite.com
. I can than check which 'virtual subdomain' is being accessed and display content accordingly.
This is to allow users to create their own account and receive their own subdomain, for example joebloggs.mysite.com
.
I understand that custom routing is achieved by inheriting from TrieNode
as per Phill Haydon's post here. Is there a way that I can access the full URL from inside the Match
method here? Or is there a better way to do this?
Upvotes: 1
Views: 682
Reputation: 4932
I would think you could do that using route conditionals: https://github.com/NancyFx/Nancy/wiki/Defining-routes#condition In the route conditions you have access to the NancyContext which gives you access to the request URL.
Upvotes: 2