mardi 11 juillet 2017

Proxy url routing in Laravel

I have been recently handed a project which has a very weird proxy routing setup in it. Basically the setup is that they have the app setup and hosted on an AWS instance which is pointed to by a domain say project.example.com. They have set this project.example.com to as their APP_URL in the env file and this all works like its supposed to. Then there comes the proxy url into play, which is basically a domain like http://ift.tt/2ub4x9y, this subfolder routing actually points to the same domain and codebase that I mentioned earlier, project.example.com. I don't actually know much about the setup of the http://ift.tt/2ub4x9y domain that is pointing to the actual codebase domain but whenever we hit it we are routed correctly.

On the laravel side what the previous devs have done is basically defined a new variable say PROXY_URL in the env file and set this as http://ift.tt/2ub4x9y and on the top of the routes.php file they do a forceRootUrl to basically set the base/app url to what has been defined in the PROXY_URL. Now I and the app are having problems due to this weird kinda routing as devs were reporting me issues previously due to urls not being made properly. The current problem I'm having is that a package for laravel to handle grid listings which is being used here, Nayjest, makes the grid properly but inside the table listing it messes up all the urls it has made, basically the urls are correct but the base urls are set in it as the old APP_URL, like http://ift.tt/2v9r9V5 when it should've been http://ift.tt/2ub4B9i. The reason I found for this was that the package was using the base url from the Request object of laravel, which on the runtime checks the servers hostname which is set to of course project.example.com, so basically not using the Laravel's Url() method to fetch the base/app url (which has now been over ridden due to forceRootUrl). Now the solution could be to ask the package's dev to change it to use Url() method, but I have seen the use of this Request object's base url in core laravel code as well (there must be a reason they are doing it which I would like to know as well).

My questions are many here, firstly this approach to handle the proxy domain, is this correct or is there a better one ? Secondly if one is using this approach how can we ask or tell the package to use the Url() method instead of the Request object's getSchemeAndHttpHost without changing the source of the package(a hack basically in our code). Thirdly are we looking straight at the problem coz I kept thinking that instead of correcting the base url in the grid listing we can keep it as it is and handle the routing of it along with query parameters correctly so we reach say from this http://ift.tt/2v9r9V5 to this http://ift.tt/2ub4B9i correctly.

Any help would be greatly appreciated, thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire