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

horizon base path and app url conflicts #1503

Conversation

AbuHuraira191
Copy link

Issue

This PR addresses the issue where Laravel Horizon's basePath is incorrectly constructed when the APP_URL has a suffix or when HORIZON_PATH is not properly handled. This causes 404 errors when accessing Horizon routes like /jobs and other resources.

Solution

  • The code dynamically constructs window.Horizon.basePath using APP_URL and HORIZON_PATH, ensuring that any suffix or prefix is handled correctly.
  • It removes trailing slashes from APP_URL and leading slashes from HORIZON_PATH to avoid double slashes in the path.
  • Adjustments are made in the router configuration to ensure compatibility with different path structures.

Example Scenarios

  1. APP_URL=https://example.com and HORIZON_PATH=horizon results in window.Horizon.basePath = 'https://example.com/horizon'.
  2. APP_URL=https://example.com/suffix and HORIZON_PATH=horizon results in window.Horizon.basePath = 'https://example.com/suffix/horizon'.
  3. APP_URL=https://example.com and HORIZON_PATH=/horizon results in window.Horizon.basePath = 'https://example.com/horizon'.

Impact

This change ensures that Horizon's base path is constructed correctly for all configurations of APP_URL and HORIZON_PATH, preventing 404 errors and enhancing compatibility for users with custom URL setups.

### Issue
This PR addresses the issue where Laravel Horizon's `basePath` is incorrectly constructed when the `APP_URL` has a suffix or when `HORIZON_PATH` is not properly handled. This causes 404 errors when accessing Horizon routes like `/jobs` and other resources.

### Solution
- The code dynamically constructs `window.Horizon.basePath` using `APP_URL` and `HORIZON_PATH`, ensuring that any suffix or prefix is handled correctly.
- It removes trailing slashes from `APP_URL` and leading slashes from `HORIZON_PATH` to avoid double slashes in the path.
- Adjustments are made in the router configuration to ensure compatibility with different path structures.

### Example Scenarios
1. `APP_URL=https://example.com` and `HORIZON_PATH=horizon` results in `window.Horizon.basePath = 'https://example.com/horizon'`.
2. `APP_URL=https://example.com/suffix` and `HORIZON_PATH=horizon` results in `window.Horizon.basePath = 'https://example.com/suffix/horizon'`.
3. `APP_URL=https://example.com` and `HORIZON_PATH=/horizon` results in `window.Horizon.basePath = 'https://example.com/horizon'`.

### Impact
This change ensures that Horizon's base path is constructed correctly for all configurations of `APP_URL` and `HORIZON_PATH`, preventing 404 errors and enhancing compatibility for users with custom URL setups.
@taylorotwell
Copy link
Member

No easily reproducible example given.

@AbuHuraira191
Copy link
Author

I was facing the same issue and I had to mention my suffix everytime in app.js
here is what I have to do
window.Horizon.basePath="/l/"+window.Horizon.path;
my app URL is
APP_URL="https://my.app.com/l"
and I mentioned
HORIZON_PATH="horizon"
it was giving me 404
before implementing this change
window.Horizon.basePath="/l/"+window.Horizon.path;

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

Successfully merging this pull request may close these issues.

2 participants