These are chat archives for gin-gonic/gin

14th
May 2015
Ryan Brooks
@ryanbyyc
May 14 2015 04:07

@manucorporat Hmmm - alright, so let's say that I want to roll out a user profile system using subdomains (ryan.mydomain.dev for example) that I plan to match against a regex. Part of the spec is to also match other subdomains such as my.mydomain.dev, admin.mydomain.dev and so forth. Using Phalcon (PHP) I would have done this with something like: $profileRouter->setHostName('((?!my|groups|admin|help)([a-z\_\-0-9]{0,20}+)).mydomain.dev'); - Alternatively in Node I would have done something like:

// Middleware 
app.use(subdomain({
    base: app.get('base'), // returns mydomain.dev
    alias: {
    '^[a-zA-Z0-9\-_]{3,30}': 'profile'
    }
}));
//Router
map.namespace('profile',  {
    subdomain: true,
    }, function(admin) {
        admin.root("apps#index", '/', {as: 'profile'});
});

However, when trying to replicate the same functionality I'm having a hard time, here is what I got: https://gist.github.com/sirstompsalot/3cebdb3ab9d3e38c395e

Which resulted in:

[GIN-debug] GET   /                         --> main.func·001 (4 handlers)
[GIN-debug] GET   /foo                      --> main.func·002 (4 handlers)
[GIN-debug] GET   /                         --> main.func·003 (4 handlers)
panic: a handle is already registered for path ''/'

Obviously this might be a httprouter issue, but I am wondering if you have any thoughts?