Play 2.0.4 Catch All Routes Always

At the end of the file of my routes, I placed the entire route to catch requests that were not previously detected, and send them to my own router (for further processing):

GET /*nameUrl controllers.Application.router(nameUrl: String) 

Of course, there are many other routes BEFORE this line. The big surprise for me is that everyone will catch every time, even if the previous route is also called, so if I open the address domain.tld/test , it displays me both logs in the Test action hit! console Test action hit! And Custom router hit! There is a simplified example:

 public static Result test() { Logger.debug("Test action hit!"); return ok(); } public static Result router(String nameUrl) { Logger.debug("Custom router hit!"); return ok(); } 

Routes (in this order)

 GET /test controllers.Application.test GET /*nameUrl controllers.Application.router(nameUrl: String) 

What I want to get:

I want to get the url for articles with my router, i.e. domain.tld/category_1/article_title without a prefix in front of it, of course, if I change, I catch everything for something stable, it will no longer receive double hits:

 GET /news/*nameUrl controllers.Application.router(nameUrl: String) domain.tld/news/category_1/article_title 

however, I really want to avoid the /news/ segment. Is it possible?

+1
source share
1 answer

I repeated it and had the same problem with Chromium (the core of Google Chrome), but not with Firefox.

With Global.java, I parsed the request.

 public class Global extends GlobalSettings { @Override public Action onRequest(Http.Request request, Method method) { Logger.info("request-path: " + request.path()); return super.onRequest(request, method); } } //output: [info] application - request-path: /favicon.ico 

For each GET / test request, Chromium attempts to load an icon.

So, include the following in conf / routes:

 GET /favicon.ico controllers.Assets.at(path="/public", file="favicon.ico") 
+6
source

All Articles