【问题标题】:Use Express Project With Apache Cordova在 Apache Cordova 中使用 Express 项目
【发布时间】:2020-05-02 20:09:28
【问题描述】:

我试图弄清楚如何使用 Apache Cordova 将现有 express.js 应用程序转换为移动应用程序。目前,我可以进入我的快递应用程序的根目录并运行“node index.js”,然后我可以在http://localhost查看当前网站。所以我想做的就是将该网站转换为可以在移动 android 设备或 ios 上运行的应用程序。我已经阅读了很多关于使用 Apache Cordova 的教程,但它们似乎都不适用于 express。

【问题讨论】:

    标签: node.js express cordova


    【解决方案1】:

    Express,在后端运行一个服务器。它不会自动转换为前端平台 Cordova。您需要使用 AJAX(JQuery、xhr、AngularJS 等)从 Cordova 调用您的 express 服务器,然后使用 Cordova 呈现网站。

    使用 JQuery 进行 AJAX 调用:

    $.ajax({
      type: "GET",
      url: `http://localhost/your/path/goes/here`,
      success: function (data) {
        // render html and/or data 
      }, error: function (err) {
        // throw error (or do something with it)
      }
    });
    

    另外,不要试图苛刻,但是你放的任何东西:http://localhost,不在你电脑上的人不能访问(除非你给他们你的 IP 地址并且正在运行该网站),请以后发布任何相关代码和/或错误消息,以便其他人可以帮助您。

    阐述我的答案的相关链接:

    Cordova and express js?

    How to convert node.js application into cordova

    示例可以参考这里:https://github.com/maximegris/express-cordova-sample(不是我的 GitHub)

    如果您想通过手机运行 express(让您的手机成为服务器):

    https://www.sitepoint.com/how-to-run-node-js-with-express-on-mobile-devices/

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-01-15
      • 1970-01-01
      • 2016-01-18
      • 1970-01-01
      • 1970-01-01
      • 2015-12-11
      • 2015-04-18
      • 1970-01-01
      相关资源
      最近更新 更多