【发布时间】:2020-07-28 19:39:37
【问题描述】:
这听起来可能很奇怪,我知道...人们会认为我应该使用 Firebase 云功能来发送邮件,是的,我确实这样做了,但没想到它只是停止发送,我找不到解决方案。
我在 Nodejs 中创建了一个服务器,并连接了我的前端以向服务器发送一个 POST 请求。现在我想将该服务器部署到 Firebase 托管,因此该服务器将与应用一起托管。
sendMessage() {
if (this.$refs.formEmail.validate()) {
this.loading = true;
this.disabled = true;
const data = {
name: this.formData.name,
email: this.formData.email,
message: this.formData.message
};
axios
.post("http://localhost:4000/sendEmail", data)
// eslint-disable-next-line no-unused-vars
.then(res => {
this.disabled = false;
this.loading = false;
this.snackbar = true;
this.successMessage = "Mail sent! We'll respond ASAP.";
this.$refs.formEmail.reset();
})
.catch(err => {
this.disabled = false;
this.loading = false;
this.snackbarError = true;
this.errorMessage = err.message;
});
}
}
那么,我有没有办法可以将该 localhost 部署到 firebase,这样可以在不打开节点上的服务器的情况下发送 post 请求
【问题讨论】:
-
您无法在 Firebase 主机上运行常规的 Node.js 脚本。您可以获得的最接近的方法是将该脚本转换为 Cloud Functions。许多 Node.js 应用程序都可以转换,但在 Cloud Functions 上打开本地帖子(您似乎就是这种情况)不是一个好的选择
-
最接近的解决方案是什么?
-
“最接近的方法是将该脚本转换为 Cloud Functions。”
标签: firebase vue.js google-cloud-functions firebase-hosting