如何将用于 React Native 应用程序的 NodeJS 服务器部署到 Heroku?
How do I deploy NodeJS server that's for a React Native App to Heroku?
我有一个使用 React Native 作为前端、NodeJS 作为后端的应用程序,它还有一个云 MySQL 实例。我想将该应用程序部署到 public 并使用 Heroku 或其他托管服务将其作为演示展示给某人。
我想用 Expo 发布我的 React Native 应用程序,但我不确定如何/在哪里托管我的 nodeJS 服务器以便移动应用程序可以访问它。
您可以按照Heroku官方文档来部署您的NodeJS服务器。
https://devcenter.heroku.com/articles/deploying-nodejs
然后您就可以像在本地主机上一样访问 Heroku 提供的域了。
将 React native/expo 应用程序部署到 heroku 的步骤:
1:将 heroku buildpack 设置为静态:>heroku buildpacks:set heroku-community/static
2:为静态构建类型添加 static.json:{ "root": "web-build/", "routes": { "/**": "index.html" } } 更多此处设置:https://github.com/heroku/heroku-buildpack-static#configuration
3: npm 运行 build (package.json: "build": "expo build:web") --> 创建 web-build 文件夹
git 添加 .
git 提交
git 推送 heroku 大师
heroku 打开
我有一个使用 React Native 作为前端、NodeJS 作为后端的应用程序,它还有一个云 MySQL 实例。我想将该应用程序部署到 public 并使用 Heroku 或其他托管服务将其作为演示展示给某人。
我想用 Expo 发布我的 React Native 应用程序,但我不确定如何/在哪里托管我的 nodeJS 服务器以便移动应用程序可以访问它。
您可以按照Heroku官方文档来部署您的NodeJS服务器。 https://devcenter.heroku.com/articles/deploying-nodejs
然后您就可以像在本地主机上一样访问 Heroku 提供的域了。
将 React native/expo 应用程序部署到 heroku 的步骤:
1:将 heroku buildpack 设置为静态:>heroku buildpacks:set heroku-community/static
2:为静态构建类型添加 static.json:{ "root": "web-build/", "routes": { "/**": "index.html" } } 更多此处设置:https://github.com/heroku/heroku-buildpack-static#configuration
3: npm 运行 build (package.json: "build": "expo build:web") --> 创建 web-build 文件夹
git 添加 .
git 提交
git 推送 heroku 大师
heroku 打开