File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff line change 4
4
5
5
use Closure ;
6
6
use Illuminate \Http \Request ;
7
+ use Illuminate \Support \Facades \Vite ;
7
8
use Symfony \Component \HttpFoundation \Response ;
8
9
9
10
class AddCspHeaders
@@ -19,8 +20,8 @@ public function handle(
19
20
return $ response ;
20
21
}
21
22
22
- // Skip CSP middleware when Laravel is rendering an exception
23
- if (config ('app.debug ' ) && $ response ->isServerError ()) {
23
+ // Skip CSP middleware when Laravel is rendering an exception or Vite is hot reloading
24
+ if (config ('app.debug ' ) && ( $ response ->isServerError () || Vite:: isRunningHot () )) {
24
25
return $ response ;
25
26
}
26
27
Original file line number Diff line number Diff line change 1
1
<?php
2
2
3
3
use Illuminate \Contracts \Http \Kernel ;
4
+ use Illuminate \Foundation \Vite ;
4
5
use Illuminate \Support \Facades \Route ;
6
+ use Mockery \MockInterface ;
5
7
use function PHPUnit \Framework \assertEquals ;
6
8
use function PHPUnit \Framework \assertFalse ;
7
9
use function PHPUnit \Framework \assertNull ;
@@ -331,6 +333,22 @@ public function configure(Policy $policy): void
331
333
assertFalse ($ headers ->has ('content-security-policy ' ));
332
334
});
333
335
336
+ test ('route middleware is skipped when vite is hot reloading ' , function (): void {
337
+ config (['app.debug ' => true ]);
338
+
339
+ $ this ->mock (Vite::class, function (MockInterface $ mock ): void {
340
+ $ mock ->shouldReceive ('isRunningHot ' )->andReturn (true );
341
+ });
342
+
343
+ Route::get ('other-route ' , function () {
344
+ return 'ok ' ;
345
+ })->middleware (AddCspHeaders::class.': ' .Basic::class);
346
+
347
+ $ headers = getResponseHeaders ('other-route ' );
348
+
349
+ assertFalse ($ headers ->has ('content-security-policy ' ));
350
+ });
351
+
334
352
it ('will handle scheme values ' , function (): void {
335
353
$ policy = new class implements Preset {
336
354
public function configure (Policy $ policy ): void
You can’t perform that action at this time.
0 commit comments