简体   繁体   English

如何在 firebase 主机上的一台服务器上部署 nodejs 服务器(发送电子邮件)和 vuejs 应用程序

[英]how to deploy nodejs server (that sends Email) and vuejs app in one server on firebase hosting

This might sound strange, I know... people will think I should have used firebase cloud function to send the Mail, Yes I did, unexpectedly, it just stopped delivery and I couldn't find a solution to it.这可能听起来很奇怪,我知道...人们会认为我应该使用 firebase 云 function 来发送邮件,是的,我确实这样做了,出乎意料的是,它只是停止了交付,我找不到解决方案。

I created a server in Nodejs and hook up my frontend to send a POST request to the server.我在 Nodejs 中创建了一个服务器,并连接了我的前端以向服务器发送一个 POST 请求。 now I want to deploy that server to firebase hosting, so the server will get hosted alongside the app.现在我想将该服务器部署到 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;
          });
      }
    }

so, is there I way I could deploy that localhost to firebase, so the post request could get sent without switching on the server on node那么,有没有我可以将该本地主机部署到 firebase 的方法,因此可以在不打开节点上的服务器的情况下发送发布请求

You cannot run a regular Node.js script on Firebase Hosting.您无法在 Firebase 主机上运行常规 Node.js 脚本。 The closest you can get is converting that script into Cloud Functions.您可以获得的最接近的方法是将该脚本转换为 Cloud Functions。

Many Node.js apps can be converted, but opening a local post (as seems to be the case for you) is not a good option on Cloud Functions.许多 Node.js 应用程序可以转换,但在 Cloud Functions 上打开本地帖子(对您来说似乎就是这种情况)不是一个好的选择。 I'd typically convert your sendEmail endpoint into a Callable or HTTPS triggered Cloud Function.我通常会将您的sendEmail端点转换为CallableHTTPS 触发的 Cloud Function。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM