简体   繁体   English

如果我在后端使用节点 js 服务器,如何将 ionic-react 应用程序部署到移动设备?

[英]how to deploy an ionic-react app to mobile if I'm using node js server in the backend?

I discovered ionic this week and I'm really considering using it at work.我这周发现了 ionic,我真的在考虑在工作中使用它。

Basically, my goal is to build an app that will work on android and Ios, where the needed functionality is to connect to the cloud over web socket and pull data from the cloud and show it on my phone.基本上,我的目标是构建一个可以在 android 和 Ios 上运行的应用程序,其中所需的功能是通过 web 套接字连接到云并从云中提取数据并在我的手机上显示。 Maybe later I'll eventually need to consider using login but not for now at least.也许稍后我最终需要考虑使用登录,但至少现在不是。

Normally, if I'm building a web app.通常,如果我正在构建 web 应用程序。 I ll use nodejs to pull the data from the cloud and expose it to the frontend.我将使用 nodejs 从云中提取数据并将其公开给前端。 I ll write all code together and I ll host my app in Heroku or something where the entry point is my nodejs server right?我将一起编写所有代码,并将我的应用程序托管在 Heroku 或入口点是我的 nodejs 服务器的地方,对吗? So that my server needs to start and it will take care of the rest.所以我的服务器需要启动,它会处理 rest。

This is a bit confusing in ionic since I need to start the app with ionic serve , but somehow I also need to start my nodejs server too right?这在 ionic 中有点令人困惑,因为我需要使用ionic serve启动应用程序,但不知何故我也需要启动我的 nodejs 服务器,对吗? So I assume I can't write the server-side code inside the ionic app or am I wrong?所以我假设我不能在离子应用程序中编写服务器端代码,还是我错了?

There is not much about this on the internet but I did some research and I guess that I should deploy (host) my nodejs server in the cloud (maybe using Heroku) and then connect to the server from my mobile app over the socket.互联网上没有太多关于此的内容,但我做了一些研究,我想我应该在云中部署(托管)我的 nodejs 服务器(可能使用 Heroku),然后通过套接字从我的移动应用程序连接到服务器。 Is this the right/only way to do this?这是正确/唯一的方法吗? are there any security issues with this method?这种方法有安全问题吗?

I find ionic great but I'm not sure if I should use it at work.我发现 ionic 很棒,但我不确定是否应该在工作中使用它。 Sincerely, this use case of using a backend server with ionic made me confused.真诚地,这个使用 ionic 后端服务器的用例让我感到困惑。

Ionic looks ideal for building cross-platform apps that does not need server-side scripting, but how complex can it be if I want to integrate some server-side code in my app? Ionic 看起来非常适合构建不需要服务器端脚本的跨平台应用程序,但是如果我想在我的应用程序中集成一些服务器端代码,它会有多复杂? especially as I said I'm going to use some login forms in the future to extend the functionality of my app.特别是正如我所说,我将来会使用一些登录 forms 来扩展我的应用程序的功能。

PS: I'm using ionic 6.10.1 and specifically I'm interested in using ionic with react not with angular. PS:我使用的是 ionic 6.10.1,特别是我有兴趣使用 ionic 与 angular 不发生反应。

After some search, I discovered that it isn't possible to deploy the frontend and backend code together.经过一番搜索,我发现无法同时部署前端和后端代码。 Therefore the trick is to deploy the nodejs server separate from the frontend.因此,诀窍是将 nodejs 服务器与前端分开部署。

Precisely, if it is a web app, then you should deploy the nodejs server in a separate host from the frontend.准确地说,如果它是 web 应用程序,那么您应该将 nodejs 服务器部署在与前端不同的主机中。 Then by starting the frontend app, you can communicate with the running nodejs server via socket or REST API.然后通过启动前端应用程序,您可以通过套接字或 REST API 与正在运行的 nodejs 服务器进行通信。

Hope this helps someone in the future:)希望这对将来的人有所帮助:)

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

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