首页 > 解决方案 > 我的前端不会与我的 Heroku 后端交互

问题描述

我有一个由 html、css 和 javascript 组成的前端,托管在 github 页面中,当连接到公共服务器时,托管与我的 heroku 应用程序相同的后端代码,工作正常,所以问题一定出在后端。我的 heroku 应用部署成功,包含:

heroku 的 php buildpack

配置文件worker: php index.php $PORT

作曲家.json:

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

作曲家生成的 composer.lock 文件(最新)

index.php 代码(我认为没有任何错误):

<?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);
?>

(我在这里省略了 api_key 和 client_URL)

有谁知道为什么这个后端不起作用?谢谢

更新:该应用程序现在连接到前端,但现在在我使用该应用程序时显示此错误:

2021-09-12T20:21:36.181818+00:00 heroku[路由器]: 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=连接=服务=状态=503字节=协议=https

标签: phpherokubackend

解决方案


推荐阅读