@@ -21,7 +21,7 @@ You can install the package via composer:
2121composer require byteflick/laravel-strict-domain
2222```
2323
24- You can publish the config file with:
24+ You can publish the config file with (Optional) :
2525
2626``` bash
2727php artisan vendor:publish --tag=" laravel-strict-domain-config"
@@ -31,45 +31,85 @@ This is the contents of the published config file:
3131
3232``` php
3333return [
34- 'domain' => env('APP_DOMAIN', 'http:// localhost'),
34+ 'domain' => env('APP_DOMAIN', 'localhost.com '),
3535];
3636```
3737
3838## Usage
3939
4040### Step 1: Configure the Environment
4141
42- You need to add an environment variable called ` APP_DOMAIN ` to your localhost.
43- The value of this variable is used for checking the desired domain name against the one in the incoming request .
42+ You need to add an environment variable called ` APP_DOMAIN ` to your ` .env ` file. The value of this variable is used
43+ for validating the incoming traffic .
4444
4545``` php
46- APP_DOMAIN=localhost
46+ APP_DOMAIN=localhost.com
4747```
4848
4949### Step 2: Apply the Middleware
5050
51- #### On Specific Routes Only
51+ #### 2.1 Redirecting External Traffic
5252
53- You can add the middleware to individual routes or apply it as a route group as well.
53+ If you want to redirect incoming traffic to your application from other domain/hosts to your own then you can
54+ use ` RedirectExternalTraffic ` middleware. This is useful when you want to redirect all the traffic from ` johndoe.com ` (
55+ referrer domain) and other domains/hosts to ` janedoe.com ` (your designated domain).
5456
55- #### Globally For Laravel 11
57+ ##### On Specific Routes Only
5658
57- Append the middleware to your default middlewares into your ` bootstrap/app.php ` via the code below.
59+ You can add the middleware to individual routes or apply it via a route group.
60+
61+ ##### Globally For Laravel 11
62+
63+ Append the middleware to your default middlewares into your ` bootstrap/app.php ` via the code below to redirect all
64+ external traffic outside your designated host to your designated host.
5865
5966``` php
6067->withMiddleware(function (Middleware $middleware) {
61- $middleware->append(CheckDomain ::class);
68+ $middleware->append(\ByteFlick\LaravelStrictDomain\Middlewares\RedirectExternalTraffic ::class);
6269})
6370```
6471
65- #### Globally For Laravel 10
72+ ##### Globally For Laravel 10
6673
67- Add the middleware to your middlewares into your ` App\Http\Kernel.php ` via the code below.
74+ Add the middleware to your default middlewares into your ` App\Http\Kernel.php ` via the code below to redirect all
75+ external traffic outside your designated host to your designated host.
6876
6977``` php
7078protected $middleware = [
71- \ByteFlick\LaravelStrictDomain\Middlewares\CheckDomain::class,
72- ];
79+ \ByteFlick\LaravelStrictDomain\Middlewares\RedirectExternalTraffic::class,
80+ ];
81+ ```
82+
83+ #### 2.2 Blocking External Traffic
84+
85+ If you want to block incoming traffic to your application from other domain/hosts to your own then you can
86+ use ` BlockExternalTraffic ` middleware. This is useful when you want to allow traffic from ` janedoe.com ` but
87+ block ` johndoe.com ` and others to your application.
88+
89+ ##### On Specific Routes Only
90+
91+ You can add the middleware to individual routes or apply it via a route group.
92+
93+ ##### Globally For Laravel 11
94+
95+ Append the middleware to your default middlewares into your ` bootstrap/app.php ` via the code below to block all
96+ external traffic outside your designated host.
97+
98+ ``` php
99+ ->withMiddleware(function (Middleware $middleware) {
100+ $middleware->append(\ByteFlick\LaravelStrictDomain\Middlewares\BlockExternalTraffic::class);
101+ })
102+ ```
103+
104+ ##### Globally For Laravel 10
105+
106+ Add the middleware to your default middlewares into your ` App\Http\Kernel.php ` via the code below to block all
107+ external traffic outside your designated host.
108+
109+ ``` php
110+ protected $middleware = [
111+ \ByteFlick\LaravelStrictDomain\Middlewares\BlockExternalTraffic::class,
112+ ];
73113```
74114
75115## Changelog
@@ -87,6 +127,7 @@ Please review [our security policy](../../security/policy) on how to report secu
87127## Credits
88128
89129- [ ByteFlick] ( https://github.com/ByteFlick )
130+ - [ ORPtech] ( https://orptech.com )
90131- [ All Contributors] ( ../../contributors )
91132
92133## License
0 commit comments