In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/02 Report--
What is rap2?
Let's talk about the cause first. at the sharing meeting last week, when talking about front-end and back-end joint debugging, some colleagues mentioned rap2 and specially went to know about it. I thought it was too convenient to use this thing for front-end and back-end interface tuning. Compared to the API Cloud developed within our company before, I prefer to use rap2.
RAP helps WEB engineers manage interface documents more efficiently through GUI tools, and automatically generates Mock data by analyzing interface structure, verifies the correctness of real interfaces, and makes interface documents become a strong dependency in the development process. With structured API data, RAP can do more, and we can avoid more duplication of effort.
The above is an excerpt from https://github.com/thx/RAP Taobao Alimama's description of rap1. You can understand at a glance that the backend formulates the API return data format, and the front end uses the interface address to mock online, avoiding the phenomenon of unilateral waiting between the front and back ends because of inconsistent progress.
Use rap2
You can directly use the online service provided by Taobao to generate an online interface address. After applying for an account, you can write and test the interface inside. I won't repeat it here.
Deploy your own rap2 service
Because rap2 is open source on github and provides a deployment solution, here's how you deploy using docker.
Premise
Install docker install docker-compose
Two open source repositories involved:
Rap2-delos: backend data API server, stamped here based on Koa + MySQL
Rap2-dolores: front-end static resources, stamped here based on React
Or use my own github repository Rynxiao/rap2-docker, which already includes these two repositories and adds the configuration.
Back-end deployment
In terms of back-end deployment, the deployment aspects that use docker have been given on github, so just follow is fine.
> mkdir rap2 > cd rap2 > git clone https://github.com/thx/rap2-delos.git> cd rap2-delos > docker-compose up-d
After running successfully, you need to initialize the database manually, and we enter the container of the object to operate:
> docker exec-it rap2-delos sh > node scripts/init > exit
Restart the service:
> docker-compose down > docker-compose up-d
You can see that the exposed port is 38080. Let's use the curl command to test whether it is successful or not. If we put it back into Hello mapped, it means that the backend has been deployed.
> curl localhost:38080
Front-end deployment
Since the front end does not provide a corresponding docker deployment method, I have to try to deploy it myself. The front end uses node for webpack packaging, so I need a node environment, so I need to pull a node image when making the container.
Because I didn't look at the deployment of the backend before deploying the frontend, I pulled a relatively new version [10.1.0] from the frontend. If you want to share a node image with the backend, you can use this node:8.11.1-alpine image.
After passing npm run build, the generated build folder is just a static resource file, so I also need to set up a server, where I start a service by installing http-server globally.
Here is the specific process:
1. Git warehouse pull
> cd rap2 > git clone https://github.com/thx/rap2-dolores.git> cd rap2-dolores
two。 Create a Dockerfile to build a new node version image
> touch Dockerfile > vim Dockerfile
The content in Dockerfile is:
# pull the version 10.1.0 node image FROM node:10.1.0# maintainer MAINTAINER ryn# to create the working directory RUN mkdir-p / home/rap2-doloresWORKDIR / home/rap2-dolores# and copy the code to the working directory COPY. / home/rap2-dolores# global installation http-server server RUN npm install-g http-server# global installation node-sass (be sure to have-- unsafe-perm, otherwise you will get an error) RUN npm install-- unsafe-perm-g node-sass# installation depends on RUN npm install# packaging RUN npm run build
3. Use docker-compose to start the service
> touch docker-compose.yml > vim docker-compose.yml
The content in docker-compose.yml is:
Version: '2.2'services: delores: # Container name container_name: rap2-dolores # use Dockerfile to build a local image build:. # build through images, the address here is not applicable for the time being, because the configuration in src/config needs to build dynamically according to your own server # image rynxiao/rap2-dolores-nodejs # specify working directory working_dir: / home/rap2-dolores # specify production environment environment:-NODE_ENV=production # launch http-server And map the port to the container interior 8081 command: / bin/sh-c 'http-server. / build-s-p 8081' privileged: true # expose port 38081 ports:-"38081 http-server"
Change the configuration in src/config/config.prod.js and point the API request address to your back-end server. Here is my configuration, which you can change as needed.
Module.exports = {serve: 'http://xxx.xxx.xxx.xx:38080', keys: [' some secret hurr'], session: {key: 'koa:sess'}}
Note that the above xxx.xxx.xxx.xxx is the ip address of your public network. If you configure a second-level domain name through port mapping, you can also remove the port number and write your second-level domain name directly. For example, if your second-level domain name is http://rap2.xxx.com, then serve can be configured as http://rap2.xxx.com.
Start the service
> docker-compose up-d
This step performs the construction of the image, using docker ps to view the latest build image, and docker-compose ps to view the running container
At this point, we can use http://{youdomain}:38081 to access rap2.
Nginx does secondary domain name conversion.
You may want to use http://rap2.{youdomain}.com to access the rap2 service we just created. Here I use nginx for address translation. The steps are as follows:
Add a Class A record to Tencent Cloud / Wanwang
I use Tencent Cloud, and the method of adding Aliyun is similar. Here, please Google yourself.
Add a server configuration to nginx
> cd / usr/local/nginx-1.13.9/conf > mkdir sites-enabled > cd sites-enabled > vim rap2. {youdomain} .com.conf
Rap2. {youdomain} .com.conf is as follows:
Server {listen 80; server_name rap2. {youdomain} .cn; access_log logs/rap2-site.log; location / {proxy_redirect off; proxy_set_header Host $host; proxy_set_header X-Real-Ip $remote_addr; proxy_set_header X-Forwarded-For $remote_addr; proxy_pass http://127.0.0.1:38081/;}}
In fact, it is a port conversion. Next, introduce it in nginx.conf
# nginx.conf http module include / usr/local/nginx-1.13.9/conf/sites-enabled/*.conf;# restart nginxnginx-s reload
Then we can use rap2. {youdomain} .com to access the rap2 service
Note: {youdomain} replace with your own domain name
Summary
I can be regarded as practicing the docker I learned before, and I have learned some knowledge in some areas that I am not familiar with through practice. Record and encourage it. I also hope that you will give us more support.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.