简体   繁体   English

为前端完全嘲弄后端逻辑是否合理?

[英]Is completely mocking the back-end logic for the front-end reasonable?

My boss asked me to find a way to completely disassociate our front-end application from the back-end in the local environment, currently I'm the sole developer for both our back-end software and the front-end, so using Docker I'm able to mimic a production environment and work on both projects separately, (we don't render on the server side), his idea is to mock literally everything, so in theory you wouldn't need the back-end software to develop the front-end. 我的老板要求我找到一种在本地环境中将前端应用程序与后端完全分离的方法,目前,我是后端软件和前端的唯一开发人员,因此使用Docker I '能够模仿生产环境并分别在两个项目上工作((我们不在服务器端进行渲染),他的想法是模拟所有内容,因此从理论上讲,您不需要后端软件来进行开发前端。

Two of the (more reasonable) solutions I've thought of are: 我想到的两个(更合理的)解决方案是:

  1. Mocking all of the network requests on the frontend, these functions will run instead of network requests. 在前端模拟所有网络请求,这些功能将代替网络请求运行。 the problem with this approach is that it is not persistent, all of the data is randomly generated for every request, and in a system that is so oriented around forms, tables, and lists, I feel that getting the data you're expecting after a form submission is a must. 这种方法的问题在于它不是持久性的,所有数据都是针对每个请求随机生成的,并且在一个围绕表单,表格和列表的系统中,我觉得在获得期望的数据之后提交表单是必须的。 and in order to persist data, every request would have to go through some sort of data store (Mobx, Redux, etc...) and even then, if the page refreshes, the data is gone. 为了保留数据,每个请求都必须经过某种数据存储(Mobx,Redux等),即使这样,如果页面刷新,数据也就消失了。
  2. Initiating an express server and DB on top of Docker along with Webpack, and mimicking the production server requests and responses using db seeders, this way the front-end is persistent. 在Docker之上与Webpack一起启动Express Server和DB,并使用db seeder模仿生产服务器的请求和响应,这样前端就具有持久性。 Obviously, this approach would generate plenty of work, and in order to make sure the express server is correctly mimicking the original back-end software, it too will need unit tests and mock requests. 显然,这种方法会产生大量工作,并且为了确保快速服务器正确地模仿原始后端软件,它也将需要单元测试和模拟请求。

While mocking the data is great for unit tests, this doesn't seem like the way of doing front-end with such a small team to me, is there a good approach to achieving this that I cant come up with or find? 虽然模拟数据对于单元测试非常有用,但对于我来说,这似乎不是与这么小的团队一起进行前端工作的方式,是否有一种很好的方法来实现我无法提出或找到的方法? or is this an exercise in poor decoupling strategies? 还是在不良的去耦策略中进行练习?

What you are looking for is a Mock API . 您正在寻找的是Mock API There's plenty of packages for it where you define example requests in a JSON format. 有很多用于它的包,您可以在其中定义JSON格式的示例请求。 A lot of these also handle persisting data for a short amount of time. 其中许多还可以在短时间内处理持久数据。

From a strategy perspective using these can actually make a lot of sense to automize end-to-end-tests, which shouldn't rely a production API. 从策略的角度来看,使用这些工具实际上对自动执行端到端测试非常有意义,因为这些测试不应该依赖生产API。 Whether it's the right choice of developer time in a one man team depends on the long-term perspective of course ;-) 在一个人的团队中,是否正确选择开发人员时间取决于长远的目标;-)

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

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