Skip to content

Commit c24f6c7

Browse files
committed
wip
1 parent cbddc78 commit c24f6c7

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

config/static.php

+9-1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@
1010
*/
1111
'driver' => 'crawler',
1212

13+
/**
14+
* Enable or disable static caching (to quickly disable the creation of the static cache without detaching the middleware).
15+
* Don't forget to clear the static cache if needed, this does does not happen using this setting.
16+
*
17+
* A good practice is to enable this setting only in production using `app()->isProduction()`.
18+
*/
19+
'enabled' => env('STATIC_ENABLED', true),
20+
1321
'build' => [
1422
/**
1523
* Clear static files before building static cache.
@@ -55,7 +63,7 @@
5563
/**
5664
* The filesystem disk that will be used to cache your pages.
5765
*/
58-
'disk' => env('STATIC_FILESYSTEM_DISK', 'public'),
66+
'disk' => env('STATIC_DISK', 'public'),
5967

6068
/**
6169
* Different caches per domain.

src/Middleware/StaticResponse.php

+6-5
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ protected function shouldBeStatic(Request $request, $response): bool
6363
{
6464
return
6565
$request->isMethod('GET') &&
66-
$response->getStatusCode() == 200;
66+
$response->getStatusCode() == 200 &&
67+
$this->config->get('static.enabled') === true;
6768
}
6869

6970
/**
@@ -121,7 +122,7 @@ public function createStaticFile(Request $request, $response): void
121122
$disk = LaravelStatic::disk();
122123

123124
if (! $disk->exists('.gitignore')) {
124-
$disk->put('.gitignore', '*'.PHP_EOL.'!.gitignore');
125+
$disk->put('.gitignore', '*' . PHP_EOL . '!.gitignore');
125126
}
126127

127128
if ($response->getContent()) {
@@ -153,15 +154,15 @@ public function basePath(Request $request): string
153154
$path = $this->getDiskPath();
154155

155156
if ($this->config->get('static.files.include_domain')) {
156-
$path .= '/'.$this->getDomain($request);
157+
$path .= '/' . $this->getDomain($request);
157158
}
158159

159160
return $path;
160161
}
161162

162163
public function getDiskPath()
163164
{
164-
return rtrim($this->config->get('filesystems.disks.'.$this->config->get('static.files.disk').'.root'), '/');
165+
return rtrim($this->config->get('filesystems.disks.' . $this->config->get('static.files.disk') . '.root'), '/');
165166
}
166167

167168
/**
@@ -191,7 +192,7 @@ protected function getFileExtension($filename, $response): ?string
191192
return null;
192193
}
193194

194-
return '.'.$extension;
195+
return '.' . $extension;
195196
}
196197

197198
/**

0 commit comments

Comments
 (0)