Skip to content

Instantly share code, notes, and snippets.

@gabrielkoerich
Created January 18, 2017 01:00
Show Gist options
  • Save gabrielkoerich/b7532a31c3894e2de9e55a3f54681fd4 to your computer and use it in GitHub Desktop.
Save gabrielkoerich/b7532a31c3894e2de9e55a3f54681fd4 to your computer and use it in GitHub Desktop.

Revisions

  1. Gabriel Koerich renamed this gist Jan 18, 2017. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion ConfigureCloudFlare → ConfigureCloudFlare.php
    Original file line number Diff line number Diff line change
    @@ -4,7 +4,6 @@

    use App;
    use Closure;
    use Exception;

    class ConfigureCloudFlare
    {
  2. Gabriel Koerich created this gist Jan 18, 2017.
    34 changes: 34 additions & 0 deletions ConfigureCloudFlare
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,34 @@
    <?php

    namespace App\Http\Middleware;

    use App;
    use Closure;
    use Exception;

    class ConfigureCloudFlare
    {
    /**
    * Set the CloudFlare conneting IP and https if applied.
    *
    * @param \Illuminate\Http\Request $request
    * @param \Closure $next
    * @return mixed
    */
    public function handle($request, Closure $next)
    {
    if (! App::environment('production')) {
    return $next($request);
    }

    if ($request->server->has('HTTP_CF_CONNECTING_IP')) {
    if ($request->isSecure()) {
    $request->server->set('HTTPS', true);
    }

    $request->server->set('REMOTE_ADDR', $request->server->get('HTTP_CF_CONNECTING_IP'));
    }

    return $next($request);
    }
    }