Files
Jobhero_back/app/Http/Middleware/Cors.php
Carlos 47f211e4ab Fix validación en hero() y CORS para ngrok
- SupplierController: corregir respuesta de error del validador, bank_account acepta numeric, rfc/bank/bank_account required al crear
- Cors: permitir header ngrok-skip-browser-warning

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-06-18 09:45:50 -06:00

40 lines
1.3 KiB
PHP
Executable File

<?php
namespace App\Http\Middleware;
use Closure;
class Cors
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
$allowedOrigins = [
'http://localhost',
'https://localhost',
'ionic://localhost',
'https://jobhero.consultoria-as.com',
'https://jobhero-api.consultoria-as.com',
'capacitor://localhost',
'http://localhost:4200'
];
$origin = $request->server('HTTP_ORIGIN');
// Allow requests from mobile apps (no origin or capacitor/ionic)
if (empty($origin) || in_array($origin, $allowedOrigins)) {
$response = $next($request);
$allowOrigin = empty($origin) ? '*' : $origin;
return $response
->header('Access-Control-Allow-Origin', $allowOrigin)
->header('Access-Control-Allow-Methods', 'GET, POST, PUT, PATCH, DELETE, OPTIONS')
->header('Access-Control-Allow-Headers', 'Content-Type, Authorization, X-Requested-With, X-XSRF-TOKEN, ngrok-skip-browser-warning');
}
return $next($request);
}
}