Home > Software engineering >  Sharing laravel 9 with ngrok cause wrong urls to be generated
Sharing laravel 9 with ngrok cause wrong urls to be generated

Time:05-23

I am building a Laravel 9 project using docker desktop on windows.

So I was trying to share my laravel project with ngrok however my css and images are not loading since laravel generates asset urls with the http prefix when I am accessing a https link given by the ngrok.

I am running my laravel 9 project with sail up -d and my ngrok with ngrok http 80.

I am able to access the site with the ngrok link but as mentioned no css and images are loaded since they are being access with an http link.

CodePudding user response:

You can force app to use https in serving asset files when the server is using https

In App\Providers\AppServiceProvider.php

public function boot()
    {
        // Fix https
        if (isset($_SERVER['HTTPS']) && ($_SERVER['HTTPS'] == 'on' || $_SERVER['HTTPS'] == 1) || isset($_SERVER['HTTP_X_FORWARDED_PROTO']) &&  $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') {
            $this->app['request']->server->set('HTTPS', true);
        }
    }
  • Related