阿里开源接口文档项目-rap2安装部署

26 篇文章 1 订阅
11 篇文章 0 订阅

目录

 

环境

下载源码

修改配置文件

后端安装部署

报错信息及解决:

运行成功

前端安装

Windows/Linux下 nodejs 进程的查看、删除


环境

  • Node.js 9.3.0
  • npm 6.14.5
  • MySQL 5.7
  • Redis 4.0
  • CentOS 7

安装可参考其他几个博客

下载源码

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

修改配置文件

进入目录:rap2-delos/src/config

目录文件如下:

├── config.dev.ts
├── config.local.ts
├── config.prod.ts
└── index.ts

修改三个config文件的mysql数据库配置和redis配置:

配置数据库新建用户,用root后面会有问题

# 创建
CREATE USER 'username'@'host' IDENTIFIED BY 'password';
# 赋权
grant all on *.* to 'username'@'%' identified by 'password';
# 刷新
FLUSH PRIVILEGES;
# 不行重启下服务

prod需要改一下redis配置

创建数据库

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

后端安装部署

cd到在rap2-delos项目目录下,操作如下命令:

cd /..

# 安装依赖包:                                 
cnpm install

# 安装 TypeScript 编译包:              
cnpm install typescript -g

# 全局安装PM2 用来启动服务端代码的 
cnpm install -g pm2

# 构建  修改了项目的代码之后一定重新编译,不然修改不起作用
cnpm run build
    
# 初始化数据库  
cnpm run create-db

# 执行mocha测试用例和js代码规范检查,可以检查项目的配置,代码的正确性。
npm run check
    
# 启动开发环境  
#cnpm run dev  ,这一步仅仅是测试下开发环境的配置,要启动项目还是在后面的 run start

#启动生产模式服务器
npm start

requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.

报错信息及解决:

# 报错信息
npm WARN ws@7.2.5 requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN ws@7.2.5 requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.3 (node_modules/pm2/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})


# 解决
npm install bufferutil@^4.0.1 babel-eslint@8 --save-dev
npm install utf-8-validate@^5.0.2 babel-eslint@8 --save-dev
npm install utf-8-validate@^5.0.2 babel-eslint@8 --save-dev

编译rap2服务端报错,明天把解决流程写下

# 报错信息
src/routes/account.ts:62:30 - error TS2345: Argument of type '{ where: {}; } & { attributes: string[]; offset: any; limit: number; order: string[][]; }' is not assignable to parameter of type 'FindOptions'.
  Types of property 'order' are incompatible.
    Type 'string[][]' is not assignable to type 'Order'.
      Type 'string[][]' is not assignable to type 'OrderItem[]'.
        Type 'string[]' is not assignable to type 'OrderItem'.
          Type 'string[]' is missing the following properties from type '[OrderItemModel, OrderItemModel, OrderItemModel, OrderItemModel, OrderItemColumn, string]': 0, 1, 2, 3, and 2 more.

上个解决信息写过了啊,怎么丢了,直接贴代码吧,src/routes/account.ts 62行

  ctx.body = {
    //data: await User.findAll(Object.assign(options, {

    data: await User.findAll(deepClone(options, {
      attributes: ['id', 'fullname', 'email'],
      offset: pagination.start,
      limit: pagination.limit,
      order: [
        ['id', 'DESC'],
      ]
    })),
    pagination: pagination,
  }
})

function deepClone(origin, target) {
    var target = target || {};
    for (var prop in target) {
        if (target.hasOwnProperty(prop)) {
            if (target[prop] !== null && typeof target[prop] === 'object') {
                origin[prop] = Object.prototype.toString.call(target[prop]) === '[object Array]' ? [] : {};
                deepClone(origin[prop], target[prop]);
            } else {
                origin[prop] = target[prop]
            }
        }

    }
    return origin;
}

运行成功

# 查询pm2进程
pm2 ls

# 拿到后端的pm2 id 为0
# 查看实时日志
pm2 logs 0

前端安装

# 获取源代码
git clone https://github.com/thx/rap2-dolores.git
 
# 修改配置文件
cd rap2-dolores/src/config
# 文件目录如下
├── config.dev.js
├── config.prod.js
└── index.js
# 修改两个配置文件的如下部分
serve: 'http://192.168.0.148:8080'
# 注意ip不能写localhost,即使是在同一个机器上写的前端和后端
 
# 回到根目录
cd ../..
# 安装依赖包
npm install

# 安装淘宝 npm
npm install -g cnpm --registry=https://registry.npm.taobao.org
# 使用cnpm 安装node-sass
cnpm install -g   node-sass

# 测试&打生产包
# 开发模式 自动监视改变后重新编译
npm run dev
     
#  测试用例
npm run test

注意:前端测试用例执行出错,错误信息包含tslint之类的,修改pakage.json里的文件,改为lint



# 编译,修改了项目的代码或配置文件之后一定重新编译,不然修改不起作用
# 如果报错说没有权限创建文件夹,可以在后面加上--unsafe-perm参数
npm run build
 
# 安装serve
npm install -g serve 
# 启动
# 其中./build是编译生成的文件路径,8090是前端访问的端口
serve -s ./build -p 8090
# 这里启动后会阻塞会话,可以使用nohup,并且指定全路径启动
nohup serve -s 全路径启动/build -p 8090 &

官方文档说可以使用serve启动项目,也可以使用nginx反向代理来路由到build包,

访问服务器8090端口:

安装报错

npm WARN deprecated tslint-react@4.2.0: TSLint has been deprecated in favor of ESLint. Please see https://github.com/palantir/tslint-react/issues/210 for more information.
npm WARN deprecated popper.js@1.16.1: You can find the new Popper v2 at @popperjs/core, this package is dedicated to the legacy v1
npm WARN deprecated chokidar@2.1.8: Chokidar 2 will break on node v14+. Upgrade to chokidar 3 with 15x less dependencies.
npm WARN deprecated core-js@2.6.11: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated core-js@1.2.7: core-js@<3 is no longer maintained and not recommended for usage due to the number of issues. Please, upgrade your dependencies to the actual version of core-js@3.
npm WARN deprecated left-pad@1.3.0: use String.prototype.padStart()
WARNING: You are likely using a version of node-tar or npm that is incompatible with this version of Node.js..lock for D:\szw\workspace\node\rap2-dolores\node_modules\.staging
Please use either the version of npm that is bundled with Node.js, or a version of npm (> 5.5.1 or < 5.4.0) or node-tar (> 4.0.1) that is compatible with Node.js 9 and above.
npm[8568]: c:\ws\src\node_zlib.cc:566: Assertion `args.Length() == 7 && "init(windowBits, level, memLevel, strategy, writeResult, writeCallback," " dictionary)"' failed.



主要是说各种不兼容,依赖弃用什么的
参考"linux和window上node.js的安装升级降级,以及cnpm代替npm"一文的npm升级package.json依赖包到最新版本号
https://blog.csdn.net/qq_44695727/article/details/106102335

实在不行的话本地打包上传

Windows/Linux下 nodejs 进程的查看、删除

因为我在测试时进程怎么都关不掉(关了一个立马重启一个),找了很久,记录下

window

查看指定端口号下的进程 :netstat -ano|findstr “端口号”
例子:3000端口

netstat -ano|findstr "3000"

根据PID获取进程名称 :tasklist|findstr PID

tasklist |findstr 5948

根据进程名称结束进程 TASKKILL 具体参数查看帮助文件

# 关闭全部
taskkill /f /t /im node.exe

liunx

pm2 ls
pm2 list
pm2 delete all


ps -ef|grep node
pkill node

最后安装成功,不知道为什么编译报一堆错,但是能运行,效果如下,先看看,后续遇到问题再说

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

瑶山

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值