简体   繁体   English

将 json-server 与使用 aws amplify 部署的反应应用程序集成

[英]Integrating json-server with a react app deployed using aws amplify

I have developed a react app with mock backend developed using json-server and had successfully tested in my local using the npm start command and was working as expected.我已经开发了一个带有使用 json-server 开发的模拟后端的反应应用程序,并已使用 npm 启动命令在我的本地成功测试,并且按预期工作。 Then i moved onto deploying the app in aws using aws-amplify and the deployment was also success.然后我开始使用 aws-amplify 在 aws 中部署应用程序,部署也成功了。 One issue that i face now is, how to make the json-server up in the aws amplify, since my all backend calls are failing now as json-server is not up.我现在面临的一个问题是,如何在 aws amplify 中启动 json-server,因为我的所有后端调用现在都失败了,因为 json-server 没有启动。 PFB the steps that i tried to integrate json-server in aws-amplify 1.In the build settings of aws-amplify i tried giving the below commands to ensure that a json-server is installed before the build and provided the command to start the json-server after '&&' to ensure the json-sever is made up after the sequence of build PFB 我尝试将 json-server 集成到 aws-amplify 中的步骤 1.在 aws-amplify 的构建设置中,我尝试提供以下命令以确保在构建之前安装 json-server 并提供启动命令'&&' 之后的 json-server 以确保 json-sever 在构建序列之后组成

  • npm install -g json-server npm install -g json-server
  • npm run build && npx json-server --watch db.json --port 3001 npm 运行构建 && npx json-server --watch db.json --port 3001

Pls.请。 let me know is there a way in which i can make the json-server up along with the aws-amplify so that my backend calls are success.让我知道有没有一种方法可以使 json-server 与 aws-amplify 一起启动,以便我的后端调用成功。 If aws-amplify is not the right option which aws service should i use to make my backend working.如果 aws-amplify 不是我应该使用哪个 aws 服务来使我的后端正常工作的正确选项。 Can i deploy a mock-service using json-server in aws ec2 and try to invoke that service from my UI.我可以在 aws ec2 中使用 json-server 部署模拟服务并尝试从我的 UI 调用该服务吗?

if you are trying to run multiple applications when you 'npm start', use concurrently npm package (for local machine testing only, not as solution to run on a remote host like AWS etc).如果您在“npm start”时尝试运行多个应用程序,请concurrently使用 npm package(仅用于本地机器测试,不能作为在 AWS 等远程主机上运行的解决方案)。

Then you can amend your package.json file to run multiple applications as below example;然后您可以修改您的 package.json 文件以运行多个应用程序,如下例所示;

  "scripts": {
    "start": "concurrently --kill-others \"react-scripts start\" \"npx json-server --watch data/db.json --port 8000\"",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },

Create a separate JSON server, then connect to it, you can do this with Heroku which offers free hosting for personal/development projects.创建一个单独的 JSON 服务器,然后连接到它,您可以使用 Heroku 执行此操作,它为个人/开发项目提供免费托管。

I have also done this for one of my previous projects on GH;我也为我之前关于 GH 的一个项目做过这个; https://github.com/rbhachu/the-mojo-blog https://github.com/rbhachu/the-mojo-blog

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

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