Skip to content

Commit da6585a

Browse files
Add ignore domains option (#11)
1 parent 90998c7 commit da6585a

File tree

4 files changed

+60
-0
lines changed

4 files changed

+60
-0
lines changed

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,18 @@ For example:
214214
],
215215
```
216216

217+
#### ☑️ Ignore Domains
218+
219+
If for any reason you wish to disable StageFront on specific doamins, you can add these to the `ignore_udomains` array in the [configuration file](#-publish-configuration-file). You can't set this in the `.env` file.
220+
221+
For example:
222+
223+
```php
224+
'ignore_domains' => [
225+
'admin.domain.com',
226+
],
227+
```
228+
217229
#### ☑️ Link Live Site
218230

219231
If you set the URL to your live site, a link will be shown underneath the login form.

config/stagefront.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,4 +157,14 @@
157157
*/
158158
'ignore_urls' => [],
159159

160+
161+
/**
162+
* The following domains will be ignored by StageFront.
163+
* Access to these domains will never be blocked.
164+
* Default: []
165+
* Example: 'admin.domain.com'
166+
*/
167+
'ignore_domains' => [
168+
],
169+
160170
];

src/Shield.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ protected function isActive()
5555
*/
5656
protected function currentUrlIsIgnored()
5757
{
58+
$ignoredDomains = Config::get('stagefront.ignore_domains', []);
5859
$ignoredUrls = Config::get('stagefront.ignore_urls', []);
5960
$ignoredUrls[] = Config::get('stagefront.url');
6061

@@ -66,6 +67,14 @@ protected function currentUrlIsIgnored()
6667
}
6768
}
6869

70+
foreach ($ignoredDomains as $url) {
71+
$url = trim($url, '/');
72+
73+
if (str_contains(Request::url(), $url)) {
74+
return true;
75+
}
76+
}
77+
6978
return false;
7079
}
7180

tests/StageFrontTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,20 @@ public function urls_can_be_ignored_so_access_is_not_denied_by_stagefront()
358358
$this->get('/public/route')->assertStatus(200)->assertSee('Route');
359359
}
360360

361+
/** @test */
362+
public function domains_can_be_ignored_so_access_is_not_denied_by_stagefront()
363+
{
364+
$this->url = Config::get('stagefront.url');
365+
366+
$this->registerRouteWithDomain('/admin', 'Admin');
367+
368+
Config::set('stagefront.ignore_domains', ['domain.example.com']);
369+
370+
$this->enableStageFront();
371+
372+
$this->call('GET', 'http://domain.example.com/admin')->assertStatus(200)->assertSee('Admin');
373+
}
374+
361375
/** @test */
362376
public function ignored_urls_can_be_accessed_by_non_whitelisted_ips()
363377
{
@@ -486,4 +500,19 @@ protected function registerRoute($url, $text)
486500
return $text;
487501
})->middleware(Config::get('stagefront.middleware'));
488502
}
503+
504+
/**
505+
* Register a test route.
506+
*
507+
* @param string $url
508+
* @param string $text
509+
*/
510+
protected function registerRouteWithDomain($url, $text)
511+
{
512+
Route::domain('domain.example.com')->group(function () use ($url, $text) {
513+
Route::get($url, function () use ($text) {
514+
return $text;
515+
})->middleware(Config::get('stagefront.middleware'));
516+
});
517+
}
489518
}

0 commit comments

Comments
 (0)