An example is if you wanted users to have their own subdomains like GitHub Pages: {username}.github.io
If the use case that you're thinking of is actually like the example (github pages), then the username would be a parameter that you might want to have accessible in your handlers, so that you can do a db lookup using the username, together with the path parameters, then figure out the response.
Given the design of echo (and every other major framework in go - httpRouter, gin, goji etc.) you can't set context values prior to routing, as the ctx is created (or grabbed from a sync.pool) inside echo.ServeHTTP().
I think that the best workaround ATM is to modify the request when you are multiplexing on subdomain, for instance, by adding the username as a url query value. Then you can grab the query value inside your echo handler.
You can use nginx proxy pass:
server {
listen 80;
server_name ~^(?<username>.+)\.github\.io$;
location / {
proxy_pass http://github.io:3000/user/$username$request_uri;
}
}
@axdg don't know if this is new or not, but you can get the host using c.Request().Host. I use this to redirect to www..
Split using strings.Split
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.