benkle/auto-preflight-bundle
config/ structure if adapted.allow_origin/allow_headers may not support dynamic values (e.g., environment-based or request-dependent CORS policies).HttpFoundation or Laravel’s Illuminate\Http for request/response handling.Bundle system with Laravel’s ServiceProvider/Middleware model.fruitcake/laravel-cors) could clash with this bundle’s logic.fruitcake/laravel-cors, barryvdh/laravel-cors, or Laravel’s native HandleCors middleware.allow_origin/allow_headers be templated (e.g., {env('FRONTEND_DOMAIN')}) or validated at runtime?VerifyCsrfToken, TrustProxies)?methods: [GET, POST] in Laravel’s routes/web.php trigger preflight responses correctly?benkle-libs) active? Are there plans for Laravel-specific updates?AutoPreflightMiddleware) that replicates the bundle’s logic using Laravel’s Request/Response classes.public function handle($request, Closure $next) {
if ($request->isMethod('OPTIONS') && $request->isPreflightRequest()) {
return response()->json([], 200, [
'Access-Control-Allow-Origin' => config('benkle_auto_preflight.allow_origin'),
'Access-Control-Allow-Headers' => config('benkle_auto_preflight.allow_headers'),
'Access-Control-Allow-Methods' => $request->route()->methods(),
]);
}
return $next($request);
}
symfony/http-foundation as a Composer dependency and adapt the bundle’s EventListener for Laravel’s events (e.g., Illuminate\Http\Events\RequestHandled).config/benkle_auto_preflight.php via a ServiceProvider:
$config = $this->app->make('config')->get('benkle_auto_preflight', []);
app/Http/Middleware/Cors.php).Route::methods() must be used to expose non-GET methods (e.g., Route::post('/api', ...)->name('api.post')).Route::apiResource()) may need explicit method definitions.AutoPreflightMiddleware before TrustProxies but after VerifyCsrfToken to avoid false positives.app/Http/Kernel.php:
protected $middleware = [
// ...
\App\Http\Middleware\AutoPreflightMiddleware::class,
\Fruitcake\Cors\HandleCors::class, // If using another CORS package
];
EventDispatcher, bind to Laravel’s Illuminate\Http\Events\RequestHandled or create a custom event.benkle/auto-preflight-bundle watch to composer.json for updates.CHANGELOG.md.\Log::info('Preflight response', [
'origin' => $request->header('Origin'),
'headers' => $request->header('Access-Control-Request-Headers'),
]);
if ($request->isPreflightRequest()) {
\Log::debug('Preflight request from ' . $request->ip());
}
| Failure Scenario | Impact | Mitigation |
|---|---|---|
| Bundle conflicts with existing CORS middleware | Preflight responses ignored or duplicated | Disable conflicting middleware; test isolation. |
Incorrect allow_origin/headers |
CORS errors in browser | Validate config against Access-Control-Allow-* headers. |
Missing methods in route definitions |
Only GET allowed | Enforce route method definitions via Laravel policy or CI checks. |
| Symfony version incompatibility | Bundle fails to load | Pin Symfony dependencies or fork the bundle. |
| PHP version mismatch | Runtime errors | Use composer.json platform constraints. |
config/benkle_auto_preflight.php.How can I help you explore Laravel packages today?