<?php

namespace App\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;

class SkipNgrokWarning
{
    /**
     * Handle an incoming request.
     */
    public function handle(Request $request, Closure $next): Response
    {
        // 1. Ambil respon halaman yang mau ditampilkan
        $response = $next($request);
        
        // 2. Jika responnya valid, sisipkan header bypass sesuai perintah Ngrok
        if (method_exists($response, 'header')) {
            $response->header('ngrok-skip-browser-warning', 'any_value');
        }

        return $response;
    }
}

