Developing a H5 client application using electron to create an HTTP service to emulate backend interface mock
In the last "electron quick start" described how to quickly start an electron application, since electron can directly use the node environment to write programs, then we can have a lot of things to deal with, such as we can do a visual front-end building tools, Or we can build a backend management system. Based on these two days, I simply made an HTTP service that emulates the backend interface.
It can do the following functions:
- It can create an HTTP local service
- It can simulate multiple requests from the backend, such as GET, post, put, delete
- JSON strings can be formatted
- You can verify the validity of the requested parameters
... And so on, usually in the back-end interface is not written well before, before and after the end of the joint adjustment, can be used, it can make your late and the end of the joint adjustment smoother, reduce inconsistencies between the front and back. Its main interface is this:
The main interface is very simple, just a few buttons, you can modify the port number, open the HTTP service, where the service is created by Express. You can then manage all the interfaces you have impersonated, all of which are stored in a local file. The interface for adding interfaces is as follows:
The URL here is localhost:8080/a/b/c, you can customize any structure, no longer need to create the corresponding folder. Parameters can also be multiple, return value, currently only a successful default return, the subsequent version will make conditional judgment return and other functions.
The management interface is as follows:
Management interface is relatively simple, mainly is the modification, deletion and preview function. The preview is to open the address with the local default browser.
A new JSON format verification feature is added here:
Later we can also be packaged JS and less functions are integrated into, basically, nodejs, electron to the infinite possibilities of the web.
Mock system:
Http://www.lovewebgames.com/app/mock/mock.exe
Http://www.react-cn.com/app/mock/mock.exe
Http://www.react-cn.com/app/mock/mock.rar
The GitHub address for this project is: Https://github.com/tianxiangbing/mock
The network download stuck when I packaged the electron, you can go to GitHub to load https://github.com/electron/electron/ Releases compress the package and copy it to the. Electron folder of the user directory, and then modify the package command to match the compression package:
Electron-packager. Mock--electron-version=0.37. 8 --asar.unpack=protocol-link.html--overwrite--platform=win32--arch=x64--icon=src/icon/favicon.ico-- out =out --version-string. filedescription='mock' --version-string. Productname='mock'
For cross-domain issues, you can use the Nginx proxy.
Using electron to develop a H5 client application create HTTP service mock backend interface mock