-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Fix app/asset URL usage #1693
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
Fix app/asset URL usage #1693
Conversation
* rename asset_url to app_url to avoid confusion due to naming * use livewire.app_url for determining the base path for JS calls * use app.asset_url for determining the path for published assets only * provide more tests
$jsonEncodedOptions = $options ? json_encode($options) : ''; | ||
|
||
$appUrl = config('livewire.asset_url', rtrim($options['asset_url'] ?? '', '/')); | ||
$appUrl = rtrim($options['app_url'] ?? config('livewire.app_url'), '/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On it's own, that didn't work for me, I changed that line to this:
$appUrl = $options['app_url'] ?? config('livewire.app_url');
$appUrl = rtrim($appUrl ?? config('app.url', '/'), '/');
Effectively, use passed $options['asset_url']
, if not that then config('livewire.app_url')
, if not that then config('app.url')
, if not that then simply /
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ralphschindler could you also set 'app_url' => config('app.url')
in livewire config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That may work(?) but I don't believe that is a good practice to suggest.
If it does work, it only works because config files happen to be processed alphabetically. Also, I don't know how well that works when config caching is taking into consideration. (and environment interpolation of values, both from files and from the actual $_ENV... lots of factors.)
I feel like sensible fallbacks are the path forward for a good out of the box experience... or let the default value be env('LIVEWIRE_APP_URL', null)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
*sidenote: if you google Laravel config within config
you get a general sense of why that's not a generally acceptable practice, even though it is not explicitly ever discussed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see - yeah, relying on load order is probably not a good idea. In the end I'd like to hear @calebporzio's thoughts on the PR before moving forward.
Good PR. However, this would be a breaking change, AND I have other reasons that I outlined in a comment at the end of this issue: #1662 Going to close this for now. I've added a link to this in the README roadmap so we can re-open for the next major version when we're ready. Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Totally solves the problem! Thanks a lot
Its my first time working with livewire ,am getting this error when i upload my project to cpanel in a subdomain "UnexpectedValueException |
1️⃣ Is this something that is wanted/needed? Did you create an issue / discussion about it first?
Yes, see #1662. Note that #1674 would also benefit from this, although this PR does not directly related to the proposal there.
2️⃣ Does it contain multiple, unrelated changes? Please separate the PRs out.
No.
3️⃣ Does it include tests, if possible? (Not a deal-breaker, just a nice-to-have)
It does :)
4️⃣ Please include a thorough description of the improvement and reasons why it's useful.
Please see #1662. The way Livewire currently uses the
asset_url
config value breaks Livewire under certain circumstances (see issue for more details). Given thatasset_url
is not used for serving (static, published) assets at all, but rather for determining the path to LW routes on the frontend, the key naming is also misleading.Note that this PR only handles the asset/app URL handling reported in #1662, it does not handle tmp files/bootstrapping mentioned in the original issue.
Consider this PR a proposed fix - I'm happy to change the implementation, so long it addresses the underlying issue.
Changes
livewire.asset_url
tolivewire.app_url
.app.asset_url
when serving published assets, regardless if on Vapor or notOther considerations
app.url
vslivewire.app_url
I initially wanted to do away with the Livewire-specific app URL configuration value entirely, because we already have
config('app.url')
(set byAPP_URL
ENV variable) available. However:APP_URL
is correctly set, it may not work in a multi-tenant app with different subdomains, where theAPP_URL
points to the main domain, but livewire is only available on a specific subdomainThen again, Laravel expects the
APP_URL
to be correctly set when you're using CLI, emails, etc anyway, so I'd be happy to remove the LW config value and simply useAPP_URL
.Deprecating
asset_url
This PR might be a breaking change for some sites (depending on their setup), so we might want to soft-deprecate the
asset_url
option instead of outright removing/renaming it and issue console warnings if it's still used?5️⃣ Thanks for contributing! 🙌