首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何集成这两个不同的后端框架?

如何集成这两个不同的后端框架?
EN

Stack Overflow用户
提问于 2019-07-13 00:33:54
回答 1查看 79关注 0票数 0

因此,我从一个朋友那里得到了一个完成了一半的网站,以帮助完成他的创业。问题是,我不知道PHP和其他开发人员离开了,并在项目中幽灵!我被困在了后面的工作中。我发现php系统很简陋,因此我使用Vue.JS和Flask重新开发了该站点的另一部分。我使用谷歌的Firebase和pythonanywhere上的Flask部署了vue.js前端。但是,主站点托管在Linode上,这是一个我也不熟悉的平台。我在想,如何将我所做的添加到主站点(这是用PHP和SQL数据库编写的),以便在Vue.js和flask中完全重新开发该站点?

所以目前,我已经从他们的git库中下载了整个文件,我基本上浏览了一下,并且有一个朋友帮我删除了他们网站上的许多冗余和bug。我不适应这种语言,所以我用Vue.JS作为前端重新开发了网站的一部分,并在firebase和Flask python上部署了前端作为后端,并使用了运行在python language上的SQLAlchemy数据库。

这是我如何调用flask api的一个片段

代码语言:javascript
运行
复制
       async setAuthenticated(login_status, user_data) {
      // Update the states
      this.logged_user_id = user_data.id;
      this.logged_user_username = user_data.username;
      this.authenticated = login_status;
      this.token = user_data.token;

      // Initialize Pusher JavaScript library
      pusher = new Pusher(process.env.VUE_APP_PUSHER_KEY, {
        cluster: process.env.VUE_APP_PUSHER_CLUSTER,
        authEndpoint: "https://theApiFrom.pythonanywhere/api/pusher/auth",
        auth: {
          headers: {
            Authorization: "Bearer " + this.token
          }
        }
      });

      // Get all the users from the server
      const users = await this.axios.get("https://theApiFrom.pythonanywhere.com/api/users", {
        headers: { Authorization: "Bearer " + this.token }
      });

      // Get all users excluding the current logged user
      this.users = users.data.filter(
        user => user.userName != user_data.username
      );

      var notifications = pusher.subscribe(
        `private-notification_user_${this.logged_user_id}`
      );

      notifications.bind("new_chat", data => {
        const isSubscribed = pusher.channel(data.channel_name);
        if (!isSubscribed) {
          const one_on_one_chat = pusher.subscribe(data.channel_name);

          this.$set(this.messages, data.channel_name, []);

          one_on_one_chat.bind("new_message", data => {
            // Check if the current chat channel is where the message is comming from
            if (
              data.channel !== this.current_chat_channel &&
              data.from_user !== this.logged_user_id
            ) {
              // Get the index of the user that sent the message
              const index = this.users.findIndex(
                user => user.id == data.from_user
              );
              // Set the has_new_message status of the user to true
              this.$set(this.users, index, {
                ...this.users[index],
                has_new_message: true
              });
            }

            this.messages[data.channel].push({
              message: data.message,
              sentiment: data.sentiment,
              from_user: data.from_user,
              to_user: data.to_user,
              channel: data.channel
            });
          });
        }
      });
    },
    getMessage: function(channel_name) {
      this.axios
        .get(`https://theApiFrom.pythonanywhere/api/get_msg/${channel_name}`, {
          headers: { Authorization: "Bearer " + this.token }
        })
        .then(response => {
          this.$set(this.messages, channel_name, response.data);
        });
    },

    chat: function(id) {
      this.active_chat_id = id;

      // Get index of the current chatting user...
      this.active_chat_index = this.users.findIndex(
        user => user.id == this.active_chat_id
      );

      // Set the has_new_message status of the user to true
      this.$set(this.users, this.active_chat_index, {
        ...this.users[this.active_chat_index],
        has_new_message: false
      });

      this.axios
        .post(
          "https://theApiFrom.pythonanywhere/api/request_chat",
          {
            from_user: this.logged_user_id,
            to_user: this.active_chat_id
          },
          { headers: { Authorization: "Bearer " + this.token } }
        )
        .then(response => {
          this.users[this.active_chat_index]["channel_name"] =
            response.data.channel_name;

          this.current_chat_channel = response.data.channel_name;

          // Get messages on this channel
          this.getMessage(response.data.channel_name);

          var isSubscribed = pusher.channel(response.data.channel_name);

          if (!isSubscribed) {
            var channel = pusher.subscribe(response.data.channel_name);

            this.$set(this.messages, response.data.channel_name, []);

            channel.bind("new_message", data => {
              //Check if the current chat channel is where the message is comming from
              if (
                data.channel !== this.current_chat_channel &&
                data.from_user !== this.logged_user_id
              ) {
                // Set the has_new_message status of the user to true
                this.$set(this.users, this.active_chat_index, {
                  ...this.users[this.active_chat_index],
                  has_new_message: true
                });
              }

              this.messages[response.data.channel_name].push({
                message: data.message,
                sentiment: data.sentiment,
                from_user: data.from_user,
                to_user: data.to_user,
                channel: data.channel
              });
            });
          }
        })
        .catch(function(error) {
          console.log(error);
        });
    },
    send_message: function(message) {
      this.axios.post(
        "https://theApiFrom.pythonanywhere/api/send_msg",
        {
          from_user: this.logged_user_id,
          to_user: this.active_chat_id,
          message: message,
          channel: this.current_chat_channel
        },
        { headers: { Authorization: "Bearer " + this.token } }
      );
    }

我正在尝试做的目标是将我创建的内容添加到主站点文件中,这样我就可以将域名配置为在活动站点下,这样人们就可以导航到我在主站点上的附加功能。我主要专注于将Vue.js (客户端)文件放到主站点文件上,因为我将webhooks指向前端部分将调用的python端。

EN

回答 1

Stack Overflow用户

发布于 2019-07-13 00:48:33

尝试使用Apache虚拟主机。

在不同的端口上运行每个站点的"php“和"flask”

然后使用apache vhost将localhost/php和localhost/flask指向localhost:ports

示例:

  • localhost:8000 <- localhost/php
  • localhost:8080 <- localhost/flask
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57010895

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档