如何在不同于Heroku的服务器上托管HTML



我在heroku上有我的index.html和必要的.js文件。一切都很好。现在,我不想把我的用户发送到";myappname.herokuapp.com";,所以我计划使用我自己的网站来存储.html文件,但当用户点击";提交";在我的HTML表单上,我想执行Herok NodeJS代码。

以下是html的

<script>
const form = document.querySelector("form");
form.addEventListener("submit", async (e) => {
e.preventDefault();
try {
displayStatus("processing...");
const request = new Request("/file-upload", {
method: "POST",
body: new FormData(form),
});
const res = await fetch(request);
const resJson = await res.json();
displayResult(resJson.result);
} catch (err) {
displayStatus("an unexpected error");
console.error(err);
}
});
function displayResult(result) {
const content = `Your ID: ${result.id}`;
displayStatus(content);
}
function displayStatus(msg) {
result.textContent = msg;
}
</script>

我怎么能称之为"/文件上传";从位于";mywebsite.com/index.html";而实际的NodeJS逻辑运行在";myappname.herokuapp.com">

我试着把"/文件上传";用";myappname.herokuapp.com/file upload"但它不起作用。

同样,目标是使用我在Heroku上拥有的东西,但不让用户去";myappname.herokuapp.com"相反,他们应该去";mywebsite.com/index.html";

谢谢

实际上,替换"文件上传";用";myappname.herokuapp.com/file upload"成功了。唯一的问题是我的";const-request=new request";请求一直返回错误,但Heroku日志显示";文件上传";

最新更新