0

I have a frontend made of html, css and javascript, hosted in github pages, which when connected to public server, hosting the same backend code as my heroku app, works fine, so the problem must be in the backend. My heroku app deployed successfully, and contains:

heroku's php buildpack

Procfile with worker: php index.php $PORT

composer.json :

{
  "require": {
    "php": "^7.4.23"
  }
}

a composer-generated composer.lock file (up to date)

the index.php code (which I dont think has any errors):

<?php
    if($_POST['action'] == "approve")
    {
        $url = 'https://api.minepi.com/v2/payments/'.$_POST['paymentId'].'/approve';
        $data = array();
    }else if($_POST['action'] == "complete")
    {
        $url = 'https://api.minepi.com/v2/payments/'.$_POST['paymentId'].'/complete';
        $data = array('txid' => $_POST['txid']);
    }
    
    $apps = array();
    $apps['auth_app1'] = 'Key <api_key>';
    $apps['auth_app2'] = 'Key <api_key>';
    $apps['auth_app3'] = 'Key <api_key>';
    $apps['auth_app4'] = 'Key <api_key>';
    
    $ch = curl_init($url);
    # Form data string
    $postString = http_build_query($data, '', '&');
    # Setting our options
    $headers = array(
       "Authorization: " . $apps[$_POST['client_URL']],
    );
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $postString);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    # Get the response
    $response = curl_exec($ch);
    $error = curl_error($ch);
    curl_close($ch);
    
    header("HTTP/1.1 200 OK");
    header('Content-Type: application/json');
    echo json_encode($response);
?>

(I've omitted api_key and client_URL here)

Does anyone know what why this backend won't work? Thanks

UPDATE: The app now connects to the frontend but now shows this error when I use the app:

2021-09-12T20:21:36.181818+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=POST path="/" host=pi-webinars.herokuapp.com request_id=d5bac079-6bc7-4bbc-b5f7-18abab21c5d8 fwd="82.7.149.74" dyno= connect= service= status=503 bytes= protocol=https

  • Can't really help you without any debugging info. Are you getting a response from the server? 500 error? Any logs? – waterloomatt Sep 12 '21 at 19:07
  • If you're fetching the data in the front end through Ajax, check the browsers console to see if you get any messages/errors about [CORS](https://stackoverflow.com/questions/7564832/how-to-bypass-access-control-allow-origin) – M. Eriksson Sep 12 '21 at 19:10
  • no response. in the logs, i just have this from the build: 2021-09-12T16:45:41.000000+00:00 app[api]: Build started by user oliver********@gmail.com 2021-09-12T16:45:50.961593+00:00 app[api]: Release v59 created by user oliver**********@gmail.com 2021-09-12T16:45:50.961593+00:00 app[api]: Deploy aa4881a8 by user oliver**********@gmail.com 2021-09-12T16:45:51.000000+00:00 app[api]: Build succeeded – Oliver Crockett Sep 12 '21 at 19:15
  • the app has to work in a Pi crypto enabled browser which doesn't support console messages. Is there any obvious error in the code or setup? Do I have to do something else to make the app run the code in index.php? – Oliver Crockett Sep 12 '21 at 19:19

0 Answers0