API管理系统RAP2部署与使用
RAP2部署
后端 rap2-delos 部署
可参考官方项目README
必要工具
- Node.js 8.9.4+
- MySQL 5.7+
- Redis 4.0+
- pandoc 2.73 (供文档生成使用)
部署步骤
- 确认 MySQL 和 Redis 服务可用。(如果没有既有资源可利用,需要自行搜索安装方法)
- yum安装pandoc(或官方网站下载)
yum install pandoc
确认安装成功
pandoc -h
- 安装 pm2,并通过 pm2 来启动 redis 缓存服务
npm install -g pm2
npm run start:redis
- 创建数据库
mysql --user <YOUR_USER_NAME> --password -e 'CREATE DATABASE IF NOT EXISTS RAP2_DELOS_APP DEFAULT CHARSET utf8 COLLATE utf8_general_ci'
- 下载最新代码
git clone https://github.com/thx/rap2-delos.git
cd rap2-delos
- 初始化
npm install --unsafe-perm
- 安装 TypeScript && 编译
npm install -g typescript
npm run build
- 初始化数据库表
npm run create-db
- 编辑服务器配置
修改src/config/config.prod.ts
中mysql和redis相关属性,指向已经准备好的数据库 - 启动服务
npm start
确认服务正常启动
浏览器输入<ip>:<端口号 默认8080>
前端 rap2-dodores 部署
可参考官方项目README
- 下载最新代码
git clone https://github.com/thx/rap2-dolores.git
cd rap2-dolores
- 初始化
npm install --unsafe-perm
- 编辑服务器配置
修改src/config/config.prod.ts
,对应之前部署的后端服务(不能用127.0.0.1) - 编译React生产包
npm run build
- 安装serve
npm install -g serve --unsafe-perm
- 运行
serve -s ./build -p 80
-p 为指定端口
后台运行
nohup serve -s ./build -p 80 &
查看服务状态、查看日志、停止服务
pm2 ls
pm2 logs rap-server-delos
pm2 stop rap-server-delos
RAP2使用方法
RAP2中存在仓库
和模块
二级结构的概念,可根据实际需要组织API的集合。
RAP2提供的功能在页面上展示的很清晰明了,不需逐个列举,以下重点介绍自动生成API响应的规则定义。
规则学习可以参照这里,下面举几个常用的例子,方便记忆。
期待结果 | 类型 | 生成规则 | 初始值 |
---|---|---|---|
32位的随机字符串 | String | 32 | 空 |
xy重复10遍 | String | 10 | xy |
1-10位的随机字符串 | String | 1-10 | 空 |
16位只含小写字母和数字 | RegExp | 空 | /[a-z0-9]{16}/ |
1-99之间的整数 | Number | 1-99 | 空 |
整数部分0-9之间小数部分1-2位 | Number | 0-9.1-2 | 空 |
真假概率相同的布尔量 | Boolean | 1-1 | 空 |
包含1-10个元素的数组 | Array | 1-10 | 空 |
自定义数组元素 | Array | 空 | [1, true, ‘hello’, /\w{10}/] |
url | String | 空 | @url |
其中@url
称为占位符,用来指示一些常用的格式,比如邮件地址、姓名、日期等。
支持的占位符如下。
分类 | 方法(@占位符) |
---|---|
Basic | boolean, natural, integer, float, character, string, range, date, time, datetime, now |
Image | image, dataImage |
Color | color |
Text | paragraph, sentence, word, title, cparagraph, csentence, cword, ctitle |
Name | first, last, name, cfirst, clast, cname |
Web | url, domain, email, ip, tld |
Address | area, region |
Helper | capitalize, upper, lower, pick, shuffle |
Miscellaneous | guid, id |