【问题标题】:how to deploy nodejs server (that sends Email) and vuejs app in one server on firebase hosting如何在 firebase 托管的一台服务器上部署 nodejs 服务器(发送电子邮件)和 vuejs 应用程序
【发布时间】: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


【解决方案1】:

您无法在 Firebase 托管上运行常规的 Node.js 脚本。您可以获得的最接近的方法是将该脚本转换为 Cloud Functions。

可以转换许多 Node.js 应用程序,但在 Cloud Functions 上打开本地帖子(您似乎就是这种情况)不是一个好的选择。我通常会将您的 sendEmail 端点转换为 CallableHTTPS triggered Cloud Function。

【讨论】:

  • 我已经这样做了,电子邮件已发送,但未发送到地址
  • 您的代码未显示电子邮件的发送方式。就像在 http://localhost:4000/sendEmail 中一样,似乎不太可能在 Cloud Functions 中/与 Cloud Functions 一起工作。
  • 谢谢你,它就像你建议的那样工作。可调用函数完成了这项工作!
猜你喜欢
  • 1970-01-01
  • 2019-02-21
  • 2022-01-14
  • 2019-01-16
  • 2013-06-16
  • 1970-01-01
  • 2016-12-07
  • 2019-10-28
  • 2020-05-04
相关资源
最近更新 更多