-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
APP_URL not taken into account : ugly hotfix #3952
Comments
👋 Thank you for opening your first issue. I'm just an automated bot that's here to help you get the information you need quicker, so please ignore this message if it doesn't apply to your issue. |
And the slightly modified fix for the FROM cachethq/docker:latest
RUN set -e; \
# HOTFIX #1: force root URL and schema
# We locate the boot() method in AppServiceProvider.php
line=$(grep -n 'public function boot(Dispatcher $dispatcher)$' /var/www/html/app/Foundation/Providers/AppServiceProvider.php | tail -n1 | cut -f1 -d:); \
\
# We insert the code 2 lines after because there is a "{" on a separate line
insertAtLine=$((line+2)); \
\
# We insert the hotfix
sed -i "$insertAtLine i \\
// Begin hotfix \n \
if (getenv('APP_URL')) { \n \
if (strpos(getenv('APP_URL'), 'https') === 0) { \n \
\\\URL::forceScheme('https'); \n \
} \n \
\\\URL::forceRootUrl(getenv('APP_URL')); \n \
} \n \
// End hotfix \n \
" /var/www/html/app/Foundation/Providers/AppServiceProvider.php; \
\
# We forward the APP_URL environment variable to FPM
echo '[www]' > /etc/php7/php-fpm.d/app-url-fix.conf; \
echo 'env[APP_URL] = $APP_URL' >> /etc/php7/php-fpm.d/app-url-fix.conf; \
\
# HOTFIX #2: fix login redirection to dashboard
# Normally it redirects to the last URL, but since Laravel is not able to detect URLs right, we force a redirection to dashboard
sed -i "s/Redirect::intended(cachet_route('dashboard'));/cachet_redirect('dashboard');/g" \
/var/www/html/app/Http/Controllers/AuthController.php; \
sed -i "s/Redirect::intended('dashboard');/cachet_redirect('dashboard');/g" \
/var/www/html/app/Http/Controllers/AuthController.php```
found how to do it based on https://laracasts.com/discuss/channels/laravel/forcescheme-or-forceschema-in-laravel-54
Merci @Thomvaill for the original fix!
Edit: Updated with updated hotfix 2 below |
And here is the correct fix for "HOTFIX #2: fix login redirection to dashboard" for v2.4:
|
Thank you so much for this :) |
Any chance of any of you doing a PR so this get's merged ? |
If anyone else comes across this, I rectified this by simply adding |
Looks like a series of recent commits broke this fix. Mostly #4071 but event just removing 'foundations' from the fix doesn't gives the same end result. |
Hello, Is an update planned to integrate these changes in a sustainable way? |
Hello, Since two week i try to make it work the ssl with CachetHQ and I just came across this topic that seems to fix the problems with SSL. I have follow the installation on cachetHQ documentation: https://docs.cachethq.io/docs/get-started-with-docker I tried to modify the Dockerfile and replace it with the following content: DockerfileFROM cachethq/docker:2.3.18
RUN set -e; \
# HOTFIX 1: force root URL and schema
# We locate the boot() method in AppServiceProvider.php
line=$(grep -n 'public function boot(Dispatcher $dispatcher)$' /var/www/html/app/Foundation/Providers/AppServiceProvider.php | tail -n1 | cut -f1 -d:); \
\
# We insert the code 2 lines after because there is a "{" on a separate line
insertAtLine=$((line+2)); \
\
# We insert the hotfix
sed -i "$insertAtLine i \\
// Begin hotfix \n \
if (getenv('APP_URL')) { \n \
if (strpos(getenv('APP_URL'), 'https') === 0) { \n \
\\\URL::forceScheme('https'); \n \
} \n \
\\\URL::forceRootUrl(getenv('APP_URL')); \n \
} \n \
// End hotfix \n \
" /var/www/html/app/Foundation/Providers/AppServiceProvider.php; \
\
# We forward the APP_URL environment variable to FPM
echo '[www]' > /etc/php7/php-fpm.d/app-url-fix.conf; \
echo 'env[APP_URL] = $APP_URL' >> /etc/php7/php-fpm.d/app-url-fix.conf; \
\
# HOTFIX 2: fix login redirection to dashboard
# Normally it redirects to the last URL, but since Laravel is not able to detect URLs right, we force a redirection to dashboard
sed -i "s/Redirect::intended(cachet_route('dashboard'));/cachet_redirect('dashboard');/g" \
/var/www/html/app/Http/Controllers/AuthController.php; \
sed -i "s/Redirect::intended('dashboard');/cachet_redirect('dashboard');/g" \
/var/www/html/app/Http/Controllers/AuthController.php``` But i have some issue: the first is : If i comment this line the i have another error: I think this is not the right solution I used to solve this ssl problem and i don't understand why it's not working. If you need i have upload my docker-compose to a better understanding of my issue. (The version of traefik is traefik v2) Do you have an idea to help me on this issue ? Regards, |
@xoxopeter I think you're getting some copy paste issues from the github formatting. After messing around with it line by line, this is what worked for me (at least for getting it to build) : FROM cachethq/docker:2.3.18
RUN set -e; \
# HOTFIX 1: force root URL and schema
# We locate the boot() method in AppServiceProvider.php
line=$(grep -n 'public function boot(Dispatcher $dispatcher)$' /var/www/html/app/Foundation/Providers/AppServiceProvider.php | tail -n1 | cut -f1 -d:); \
\
# We insert the code 2 lines after because there is a "{" on a separate line
insertAtLine=$((line+2)); \
\
# We insert the hotfix
sed -i "$insertAtLine i \\ \
if (getenv('APP_URL')) { \n \
if (strpos(getenv('APP_URL'), 'https') === 0) { \n \
\\\URL::forceSchema('https'); \n \
} \n \
\\\URL::forceRootUrl(getenv('APP_URL')); \n \
} \n \
" /var/www/html/app/Foundation/Providers/AppServiceProvider.php; \
\
# We forward the APP_URL environment variable to FPM
echo '[www]' > /etc/php7/php-fpm.d/app-url-fix.conf; \
echo 'env[APP_URL] = $APP_URL' >> /etc/php7/php-fpm.d/app-url-fix.conf; \
\
# HOTFIX 2: fix login redirection to dashboard
# Normally it redirects to the last URL, but since Laravel is not able to detect URLs right, we force a redirection to dashboard
sed -i "s/Redirect::intended(cachet_route('dashboard'));/cachet_redirect('dashboard');/g" \
/var/www/html/app/Http/Controllers/AuthController.php; \
sed -i "s/Redirect::intended('dashboard');/cachet_redirect('dashboard');/g" \
/var/www/html/app/Http/Controllers/AuthController.php |
Thank you for your input on Cachet 2.x. We are shifting our attention and resources to Cachet 3.x and will no longer be supporting the 2.x version. If your feedback or issue is relevant to the 3.x series, we encourage you to engage with the new branch. For more information on the Cachet rebuild and our plans for 3.x, you can read the announcement here. We appreciate your understanding and look forward to your contributions to the new version. |
Hello,
I am running Cachet behind an ALB, which is itself behind an HAProxy (because exposed on an intranet).
The ALB performs the SSL termination and the HAProxy exposes Cachet on a custom port.
As a result, Cachet is completely confused when generating its URLs:
http://
instead ofhttps://
I thought the
APP_URL
would solve my issue, but it is unfortunately not taken into account at all.A lot of issues reference this problem:
Each time, we see only one solution: patch a file with
\URL::forceSchema('https');
...Unfortunately, the solution, in addition to being ugly, is not complete because the redirection after login to the dashboard is still not fixed.
So, for those who might be interested, here is how I managed to patch the Docker image to make it fully work:
Of course, this is ugly and works only for a specific version of Cachet.
Is it possible to implement this fix correctly?
The text was updated successfully, but these errors were encountered: