Coder Social home page Coder Social logo

laravel-cloudflare's Introduction

Trust Cloudflare's Proxies for Laravel

Add Cloudflare ip addresses to trusted proxies for Laravel.

Latest Version Downloads Circle CI Coverage Status

Installation

Install using composer:

composer require monicahq/laravel-cloudflare

You don't need to add this package to your service providers.

Add the middleware in app/Http/Kernel.php, adding a new line in the middleware array:

\Monicahq\Cloudflare\Http\Middleware\TrustProxies::class

Existing Laravel application

This middleware uses fideloper/proxy as a backend, so you can remove the other TrustProxies line from the middleware array.

Another option is to extend the App\Http\Middleware\TrustProxies class to Monicahq\Cloudflare\Http\Middleware\TrustProxies:

namespace App\Http\Middleware;

use Illuminate\Http\Request;
use Monicahq\Cloudflare\Http\Middleware\TrustProxies as Middleware;

class TrustProxies extends Middleware
{
    ...

If the cloudflare ips are detected, they will be used, and if not the trustproxies one will be.

Refreshing the Cache

This package basically retrieves Cloudflare's IP blocks, and stores them in cache. When request comes, the middleware will get Cloudflare's IP blocks from cache, and load them to trusted proxies.

Thus, you'll need to refresh the cloudflare cache every day

You can use the following command for this:

php artisan cloudflare:reload

Suggestion: add the command in the schedule

Add a new line in app/Console/Kernel.php, in the schedule function:

$schedule->command('cloudflare:reload')->daily();

View current Cloudflare's IP blocks

You can use the following command to see the cached IP blocks.

php artisan cloudflare:view

Option: publish the package config file

If you want, you can publish the package config file to config/laravelcloudflare.php:

php artisan vendor:publish --provider="Monicahq\Cloudflare\TrustedProxyServiceProvider"

This file contains some configurations, but you may not need to change them normally.

Support

This package supports Laravel 5.5 or newer.

License

This repository licensed under the MIT license.

Citations

This package was inspired by lukasz-adamski/laravel-cloudflare and forked from ogunkarakus/laravel-cloudflare.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.