简体   繁体   中英

Intercept web request for playframework an /address that does not exist

How can I intercept all web requests to playframework ( have all requests to /something or /other redirected to a same controller ) and in that controller get the calling address path (ex. /something or /other )?

So I can use it to load different environment settings based in the requested path.

You can do that by just adding a "catch-all" route as last route (in your routes file):

GET /*path controllers.Stuff.catchAll(path)

You can also do it for a specific path:

GET /something/*path controllers.Stuff.somethingCatchAll(path)

The path variable passed to your controller is the actual path. From the controller, you can also inspect the request object as always to get more details.

relevant doc: https://playframework.com/documentation/2.6.x/ScalaRouting#Dynamic-parts-spanning-several-/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM