从Heroku网站获取



我已经创建了一个Web应用程序,该应用程序允许用户输入其电话号码,然后单击Enter以接收我从Twilio购买的号码的呼叫。它通过从我的Localhost DB中获取电话号码来做到这一点。我现在在Heroku服务器上拥有Web应用程序。但是,当我单击呼叫时,我会得到这些错误。

"无法加载资源:找不到带有指定主机名的服务器。"

"未经手的承诺拒绝:typeError:类型错误"

当我从当地主持人那里获取它时,它运行良好,但现在我有问题。谁能告诉我为什么会发生这种情况?

谢谢

JS文件

const express = require("express");
const app = express();
const port = 3000;
app.get("/", function(req, resp){
resp.sendFile(__dirname+"/input.html");
});

app.get("/:data", function(req, resp){
var accountSid = 'accountsid'
var authToken = 'tokensid'
var client = require('twilio')(accountSid, authToken);
client.calls.create({
url: 'https://demo.twilio.com/docs/voice.xml',
to: req.params.data,
from: '3738373839',
});

html文件

<input type="text" placeholder="Enter your number" id="inputNum" />
<button id="submitNum">Enter</button>
<script>

submitNum.addEventListener("click", function(){
var inputNum = document.getElementById("inputNum");
var submitNum = document.getElementById("submitNum");
var phoneNumber = inputNum.value;
fetch("https://******.herokuapp.com" 
+ phoneNumber).then((resp)=>{
console.log(resp);
});
});
</script>

假设这些不是错字,"http://https://******.herokuapp.com"不是有效的服务器(两次注意http)。我建议将其更改为"/" + phoneNumber,以便在该网站的当前主机(Localhost或Heroku)使用。

单独的样式,您应该将twilio客户端放在您的获取功能之外,以便仅创建一次,而不是每次有人调用端点时。