rap2安装部署笔记

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xuxile/article/details/85279738

1.简介
RAP2是在RAP1基础上重做的新项目,它包含两个组件(对应两个Github Repository)。
rap2-delos: 后端数据API服务器,基于Koa + MySQLlink
rap2-dolores: 前端静态资源,基于React link
官方演示demo地址:http://rap2.taobao.org/
2.获取源代码

git clone https://github.com/thx/rap2-delos.git
git clone https://github.com/thx/rap2-dolores.git

3.安装部署后端API服务器
3.1环境要求
    Node.js 8.9.4+
    MySQL 5.7+
    Redis 4.0+
3.2准备工作
node.js安装参考:http://www.runoob.com/nodejs/nodejs-install-setup.html
mysql安装参考:https://blog.csdn.net/xuxile/article/details/82912513
redis安装参考:https://blog.csdn.net/xuxile/article/details/52679353
3.3创建创建数据库

CREATE DATABASE IF NOT EXISTS RAP2 DEFAULT CHARSET utf8 COLLATE utf8_general_ci;

3.4配置文件
目录:rap2-delos/src/config
文件:config.dev.ts;其中dev,表示开发环境,其他同理
修改:config.dev.ts文件中db对象中username,password参数与本地或者开发环境的数据库信息匹配
3.5安装依赖包
项目根目录下执行:

npm install

3.6安装TypeScript模块

npm install -g tslint typescript

3.7编译源码

npm run build

3.8初始化数据库
项目根目录下执行:

npm run create-db

3.9启动服务
开发模式(监视并在发生代码变更时自动重启):

npm run dev

生产模式:

npm start

启动成功终端会提示如下:

[PM2] Process successfully started
┌──────────────────┬────┬──────┬───────┬────────┬─────────┬────────┬─────┬──────────┬──────┬──────────┐
│ App name         │ id │ mode │ pid   │ status │ restart │ uptime │ cpu │ mem      │ user │ watching │
├──────────────────┼────┼──────┼───────┼────────┼─────────┼────────┼─────┼──────────┼──────┼──────────┤
│ rap-server-delos │ 0  │ fork │ 53223 │ online │ 950     │ 0s     │ 0%  │ 9.3 MB   │ root │ disabled │
└──────────────────┴────┴──────┴───────┴────────┴─────────┴────────┴─────┴──────────┴──────┴──────────┘

访问浏览器会提示 RAP2后端服务已启动,请从前端服务(rap2-dolores)访问。
4.安装部署前端静态资源
4.1配置文件
目录:rap2-dolores/src/config
文件:config.dev.js;其中dev,表示开发环境,其他同理
修改:config.dev.js文件中后端接口地址根据需要修改
4.2安装依赖包
切换到根目录:

npm install

4.3编译源码
切换到根目录:

npm run build

4.4安装serve

npm install -g serve

4.4启动服务
用serve命令或nginx服务器路由到编译产出的build文件夹作为静态服务器即可
后台运行:

serve -s ./build -p 18081 &

4.5常见问题
错误提示:

gyp ERR! configure error gyp ERR! stack Error: EACCES: permission denied,
mkdir '/data/server/rap2-dolores/node_modules/node-sass/.node-gyp'

解决方案:

在项目根目录创建.npmrc文件,复制下面代码到该文件:
phantomjs_cdnurl=http://cnpmjs.org/downloads
sass_binary_site=https://npm.taobao.org/mirrors/node-sass/
registry=https://registry.npm.taobao.org
删除之前安装node-sass包
npm uninstall node-sass
重新安装
npm install -g node-sass -unsafe-perm

执行成功后 再执行:

npm install

4.6参考资料
占位符可参考:
https://blog.csdn.net/u011613356/article/details/81087238?utm_source=blogxgwz3
占位符     解释
@cname     中文人名
@id     身份证id
@title     中文title
@city     中文城市
@ip     ip 地址
@email     email
@url     url地址
@csentence(1,5)     生成1到5个字的中文句子
@cparagraph     生成中文段落
@string(11)     输出11 个字符长度的字符串
@float(0,10)     0 到 10 的浮点数
@integer(60,70)     60 到 70 之间的整数
@boolean     boolean 类型 true,false

猜你喜欢

转载自blog.csdn.net/xuxile/article/details/85279738