I have 3 route files, namely web.route, admin.routes and swift.routes respectively. Each of this routes file is represent a subdomain and should be changed based on the URI subdomain path. Play Java pls!
public Handler onRouteRequest(RequestHeader requestHeader) {
String host = requestHeader.getHeader(Http.HeaderNames.HOST);
Pattern pattern = Pattern.compile("^([a-z0-9]+)\\.([a-zA-Z0-9_%*:.]+)");
Matcher matcher = pattern.matcher(host);
if (matcher.matches()) {
String subDomain = matcher.group(1);
if (subDomain.equalsIgnoreCase("swift")) {
//use swift routes file
} else if(subdomain.equalsIgnoreCase("admin")) {
//use the admin routes file
} else {
//use the web route for all other subdomain or non-subdomain
}
}
return super.onRouteRequest(requestHeader);
}
I have seen number of question online that discuss about this, but none was detailed enough and perhaps this is play framework 2.4 all the one I have seen are play 1 and play scala. I also understand the best approach to get this done is via SbtProject https://www.playframework.com/documentation/2.2.x/SBTSubProjects However I don't have the luxury to go through that approach. Any help will be appreciated.