Skip to content

Skip PreventBrowserAccess middleware when running tests #551

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Http/Middleware/PreventRegularBrowserAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ class PreventRegularBrowserAccess
{
public function handle(Request $request, Closure $next)
{
if (! config('nativephp-internal.running')) {
return $next($request);
}

// Explicitly skip for the cookie-setting route
if ($request->path() === '_native/api/cookie') {
return $next($request);
Expand Down
7 changes: 7 additions & 0 deletions src/NativeServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use Illuminate\Console\Application;
use Illuminate\Foundation\Application as Foundation;
use Illuminate\Foundation\Http\Kernel;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\DB;
Expand All @@ -23,6 +24,7 @@
use Native\Laravel\Events\EventWatcher;
use Native\Laravel\Exceptions\Handler;
use Native\Laravel\GlobalShortcut as GlobalShortcutImplementation;
use Native\Laravel\Http\Middleware\PreventRegularBrowserAccess;
use Native\Laravel\Logging\LogWatcher;
use Native\Laravel\PowerMonitor as PowerMonitorImplementation;
use Native\Laravel\Windows\WindowManager as WindowManagerImplementation;
Expand Down Expand Up @@ -84,6 +86,11 @@ public function packageRegistered()
Handler::class
);

// Automatically prevent browser access
$this->app->make(Kernel::class)->pushMiddleware(
PreventRegularBrowserAccess::class,
);

Application::starting(function ($app) {
$app->resolveCommands([
LoadStartupConfigurationCommand::class,
Expand Down
Loading