<?php

namespace App\Http\Middleware;

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

class BypassNgrok
{
    /**
     * Handle an incoming request.
     */
    public function handle(Request $request, Closure $next): Response
    {
        $response = $next($request);

        // Menggunakan method header() yang lebih aman untuk objek Response Laravel
        if (method_exists($response, 'header')) {
            $response->header('ngrok-skip-browser-warning', 'true');
        } else {
            // Backup jika response adalah instance Symfony Response biasa
            $response->headers->set('ngrok-skip-browser-warning', 'true');
        }

        return $response;
    }
}

