laravelherokuquotaguard

how to work locally with laravel when third-party api need only production IP to whitelist?


The scenario like this, I deployed my laravel app to heroku. The third-party api needs my production IP for whitelisting in order to use their resources. Heroku doesn't provide ip, I use add on to get ip. It connected ok between my app to third-party now. The problem is that, when I clone my app to local and start to run and test locally, it give error. (Undefined index: host) My code is below

    $testparam = 'q='.$q.'&s='.$s;
    $quotaguard_env = getenv("QUOTAGUARDSTATIC_URL");
            $quotaguard = parse_url($quotaguard_env);
    
            $proxyUrl       = $quotaguard['host'].":".$quotaguard['port'];
            $proxyAuth       = $quotaguard['user'].":".$quotaguard['pass'];
    
            $url = "http://xxxxx.com/api/resource";
    
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, $url);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
            curl_setopt($ch, CURLOPT_PROXY, $proxyUrl);
            curl_setopt($ch, CURLOPT_PROXYAUTH, CURLAUTH_BASIC);
            curl_setopt($ch, CURLOPT_PROXYUSERPWD, $proxyAuth);
            curl_setopt($ch, CURLOPT_POSTFIELDS,$testparam);
    
            $response = curl_exec($ch);
            $xml = simplexml_load_string($response);
            $json = json_encode($xml);
            $array = json_

decode($json,TRUE);
        dd($array);

Currently, I have to push my file to heroku after I write one or two lines of code in order to see the result. Is there any way to write and test locally?


Solution

  • You need to set the QUOTAGUARDSTATIC_URL environment variable to what is in the QuotaGuard Admin dashboard or in Heroku's heroku config -a APPNAME command.