Skip to content

Instantly share code, notes, and snippets.

@tzurbaev
Created May 31, 2017 14:13
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tzurbaev/350cfd495d8e3bf6f0a505683a861f47 to your computer and use it in GitHub Desktop.
Save tzurbaev/350cfd495d8e3bf6f0a505683a861f47 to your computer and use it in GitHub Desktop.
Laravel Middleware for LocalTunnel URLs rewriting
<?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