Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Determine Root URL at runtime rather than at time of generation. #41

Open
mdwheele opened this issue Oct 26, 2016 · 2 comments
Open

Determine Root URL at runtime rather than at time of generation. #41

mdwheele opened this issue Oct 26, 2016 · 2 comments

Comments

@mdwheele
Copy link

mdwheele commented Oct 26, 2016

Currently, rootUrl is compiled from APP_URL when laroute:generate is executed. As far as I can tell, rootUrl is only ever used when laroute.absolute is false (default). Otherwise, it is not needed.

Using relative path generation assumes URIs are mounted under the domain name, not considering an application that might be hosted in a subdirectory of that domain. Laravel's UrlGenerator doesn't care much about this because it relies on Symfony's Request to generate a correct URI up to the point it takes over. Using absolute URLs when generating is a way around this since JavaScript has no way of telling the difference between what's a subdirectory and what's route.

Here's my specific problem:

  • I do local development on an application and I serve it from http://local.dev.
  • My production environment is hosted from http://example.org/application.
  • I use webpack to handle the bundling of the resultant laroute.js file generated by this package. I do not bundle assets in production; thus, the only .env available at compile-time is my local one.

So, if I pack everything up locally and use absolute URLs, I end up with a production application attempting to query http://local.dev/generated/path when in fact, I want http://example.org/application/generated/path. Previous to discovering this package, I was doing something fairly similar: creating a JavaScript object populated with data from the backend. The difference was that I didn't need to support parameterized routes during prototyping and now I do, so I'm delighted to find this package! 😁

However, I would like to contribute a means of determining root URL at runtime, based on either the .env#APP_URL configuration OR by generating it and disregarding what is in .env#APP_URL.

All this to say, would you be interested in such a contribution and if so, do you have any specific constraints towards development? I've got a local patch that works for me but it requires something like this in my base template (which actually works alright and is reasonable, to me):

<script src="{{ asset("public/js/laroute.js") }}"></script>
<script>
    laroute.config.rootUrl = "{{ env('APP_URL') }}"
</script>

Essentially, exposing configuration to userland to be changed at runtime, while also allowing compile-time generation from your published vendor configuration.

@mdwheele
Copy link
Author

Related: #20

@TylerVigario
Copy link

Any progress on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants