playframework, can you route on hostname/subdomain

2019-02-07 12:04发布

问题:

We are porting a seam app(2 apps) to one play app to test out play right now(well, porting harder scenarios...so far, so good).

We would like to be able to route on hostname though for the root / directory. For http://alvazan.com/ we want to route to our home.html page but for

http://*.premonitionx.com/ we want to route to the dashboard(which redirects to login page if not logged in).

Lastly, we want to route http://premonitionx.com/ to redirect to alvazan.com web page.

Also, we would LOVE a route like

http://{company}.premonitionx.com/{project}/{release}

Is that even possible in the playframework???? In dev mode, we have these urls right now for developing in seam to use

http://{company}.dev.premonitionx.com such that we can test on our local machine and test out different companies, etc. etc. (as you know many tests can't be tested if it is always localhost)

thanks, Dean

回答1:

some of the docs are more difficult to find for play :) I couldn't find this in any of the real documentation but remembered it being part of a release...

http://www.playframework.org/documentation/1.1/releasenotes-1.1#routeHost


Virtual hosting in routes

The routes file now supports Host matching. this can be useful if action parameters must be extracted from the host parameter. For example, for a SAAS application, you could use:

GET {client}.mysoftware.com/ Application.index

and then automatically retrieve the client value as for any other request parameter:

public static void index(String client) { ... }