php - 我的前端不会与我的 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
解决方案
推荐阅读
- javascript - 尝试在 Vue 中将 props 传递给孩子:“Expected String with value ”[object Object]“, got Object”
- react-native - 如何在反应导航中隐藏标签导航的标题?
- javascript - 使用 js-upload-photos 按钮在 Django 模板中提交文本字段
- c# - .Net Core 防止在 += 运算符期间分配内存
- spring-boot - 如何禁用 configserver Health 页面检查默认标签 git
- python - 我在 Codechef 中运行 Python 代码,但无法找出代码倒数第二行中的错误。有人可以发现错误吗?
- tensorflow - 使用 keras API 的 tensorflow 可学习权重系数
- angular - Angular:打开起始页时如何读取 URL 字符串中的参数?
- kubernetes - 边车注入后网络策略入口不起作用
- cors - 调用 3rd 方 API 时处理 CORS