0

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?

1 Answers1

0

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.

QuotaGuard
  • 50
  • 5
  • It looks something like this, QUOTAGUARDSTATIC_URL: http://xxxxxxxxxxxxxxxxxxxxxxxxx@us-east-static-10.quotaguard.com:9293. What do you mean to set to what is in the QuotaGuard Admin? In there, I have two IP addresses. –  Jul 26 '22 at 03:08
  • 1
    Correct, so that connection string should be added to your code so your traffic passes through the proxies. The two IP's you see are your two load balanced IP's that will be used when you pass traffic through the proxy using that connection string you find in your dashboard. – QuotaGuard Jul 26 '22 at 19:55