开发者

how to redirect to other port in playframework

开发者 https://www.devze.com 2023-02-18 05:00 出处:网络
can anyone tell me how to redirect to a module using another port? example: redirect from http://localhost:9000 to https://loca开发者_运维技巧lhost:9443/login

can anyone tell me how to redirect to a module using another port? example: redirect from http://localhost:9000 to https://loca开发者_运维技巧lhost:9443/login

without changing ports, i'd just use @{Secure.login()} in the controller but i couldn't find any way to redirect to another port..?


The way you are meant to do this, for your example, is to the .secure() method. It was added in Play 1.0.3.2.

So it would look like

@{Secure.login().secure()}

This is a special method on the router object that changes the URL from HTTP to HTTPS. The last time I checked though, it didn't change the port. I raised a bug, but not sure if it is not fixed in the 1.2 master branch yet (https://github.com/playframework/play/blob/master/framework/src/play/mvc/Router.java).

The reason for this, is that play expects an HTTP server to sit infront of Play in a production environment, and handles HTTPS for you, and proxies through to Play as a simple HTTP request. The purpose of the .secure() is to tell the URL to switch to HTTPS, but still go through the same domain.

I don't think there are many alternatives (and none that are nice and simple).

  • You could take the Play source, and altering the Router.java file, so that it also changes the port number (in the secure method).

  • Or, you could write a FastTag that mimics the Router.reverse (effectively what the @ symbol does), but replace the port number with a secure one.


As codemwnci explained, in prod, generally Play is behind a front proxy that manages all secured channel issues and which can also be used for balancing.
The @{Secure.login().secure()} should work but it only changes http to https.
In addition, I would add the dumb cludge that can be used in a Controller:

redirect("http://www.zenexity.fr:9876");

;)

0

精彩评论

暂无评论...
验证码 换一张
取 消