Created
May 31, 2017 14:13
-
-
Save tzurbaev/350cfd495d8e3bf6f0a505683a861f47 to your computer and use it in GitHub Desktop.
Laravel Middleware for LocalTunnel URLs rewriting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Support\Facades\URL; | |
use Illuminate\Support\Str; | |
class LocalTunnelMiddleware | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
$host = $request->header('host'); | |
if (Str::contains($host, 'localtunnel.me')) { | |
$usingProtocol = $request->header('x-forwarded-proto') === 'https' ? 'https' : 'http'; | |
URL::forceScheme($usingProtocol); | |
config('app.url', $host); | |
} | |
return $next($request); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment