Code Monkey home page Code Monkey logo

service-mw2's People

Contributors

carb-x avatar codacy-badger avatar czy88840616 avatar fossabot avatar luojiyin1987 avatar tkvern avatar verncake avatar waitingsong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

service-mw2's Issues

rabbitmq文件ts检查无法通过

项目未做任何修改,

运行环境

yarn

docker-compose up -d
# 修改数据库的操作做了,这里忽略不写

yarn dev

然后就报错了。

如下第四行所示

  // src/app/service/rabbitmq.ts > RabbitmqService > connect
  async connect() {
    // 创建连接
    // @ts-ignore 这一行必须添加忽略注释才能通过
    this.connection = await amqp.connect(this.rabbitmq.url);

    // 创建 channel
    this.channel = await this.connection.createChannel();

    // 绑定队列
    await this.channel.assertQueue('my-queue', {
      exclusive: true,
      autoDelete: true,
    });
    // 绑定交换机
    await this.channel.bindQueue('my-queue', 'my-exchange', 'create');

    return this.connection;
  }

错误提示

[ Midway ] start error: ⨯ Unable to compile TypeScript:
src/app/service/rabbitmq.ts(29,5): error TS2740: Type 'IAmqpConnectionManager' is missing the following properties from type 'Connection': createConfirmChannel, off, removeAllListeners, setMaxListeners, and 6 more.

我对rabbitmq使用不多,也不知道这是个什么情况,但项目刚运行就报错。使用是docker安装的环境,忽略类型检查之后就能正常通过。

看了一些type类型定义,确实接口是对不上的,但amqp里有一个 connection 的 getter ,类型是 connection 所以能对上,但是它是 undefined 。

base model中id为string的意义?

base model中id为string的意义是什么?数据库id不是基本都是int或者bugint类型?这里数据模型id也应该是number才是啊,为啥是string。求科普一下

数据库存储array list和string的转换

如果给ts定义number list,装饰器定义varchar,在service是可以解析到变量有两种类型。
但是在model当前文件是解析不到的。
image
image
即使在上述支持的情况下,转换数据类型也是会被ts捕捉的,毕竟split不存在于number list中。
这种涉及序列化的场景,有什么好的解决方案吗,我看了案例中的转换,属于强转,感觉与any无异。

redis连接超时

redis设置无密码和有密码都测试了,都提示连接超时

2020-12-24 12:23:49,281 ERROR 21990 nodejs.ETIMEDOUTError: connect ETIMEDOUT
at Socket. (/home/guo/development/javascript/midwayjs/project/service-mw2/node_modules/_ioredis@4.19.4@ioredis/built/redis/index.js:308:37)
at Object.onceWrapper (events.js:421:28)
at Socket.emit (events.js:315:20)
at Socket.EventEmitter.emit (domain.js:486:12)
at Socket._onTimeout (net.js:483:8)
at listOnTimeout (internal/timers.js:554:17)
at processTimers (internal/timers.js:497:7)
errorno: "ETIMEDOUT"
code: "ETIMEDOUT"
syscall: "connect"
name: "ETIMEDOUTError"

对 jwt auth 示例的一点小小建议

const { payload } = ctx.app.jwt.decode<{ id: number }>(token);

这里建议把 decode(...) 换成 verify(...),因为可能出现小白错误理解的情况,而且 auth 的场景也确实应该使用 verify 😅。

Reference

Warning: When the token comes from an untrusted source (e.g. user input or external requests), the returned decoded payload should be treated like any other user input; please make sure to sanitize and only work with properties that are expected
警告:当令牌来自不受信任的来源(例如用户输入或外部请求)时,应将返回的解码负载视为任何其他用户输入; 请确保进行消毒并仅使用预期的属性(纯机翻 😁)

jwt问题

image
大佬 接口如果不想用鉴权只能在这里配置么,不能像egg那样写在router中引入中间件么

数据库连接失败

运行 npm run dev; 报错数据库连不上
Host 'host.docker.internal' is not allowed to connect to this MySQL server
我找到一个问题地址,不太理解
我安装了docker desk

在自己定义的函数里使用assert并用MyError抛错,没有被全局捕获到,报unhandledRejectionError

测试了一下,dto不符合入参要求,或者controller里的MyError抛错都可以被全局的error-handler捕获到,不知道为啥自定义的函数里,没有被捕获到?自定义的函数主要也是在controller里调用的,比如在helper里定义了一个公共函数,相关校验没有通过,使用类似
const record = xxx;
assert(record, new MyError('您没有相关的操作权限', 403));
return true;
预期效果:如果record为空,MyError被捕获到,并中断处理流程
实际效果:仅在后台报了unhandledRejectionError,未中断处理流程,返回给前端的是200

npm v7 执行 install 时会出现依赖报错

npm v6 执行安装(本来用v7然后版本回退改用v6)

➜  service-mw2 git:(master) ✗ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @types/[email protected]
npm ERR! node_modules/@types/jest
npm ERR!   dev @types/jest@"^26.0.24" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @types/jest@"^27.0.0" from [email protected]
npm ERR! node_modules/ts-jest
npm ERR!   dev ts-jest@"^27.0.4" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/xmo/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/xmo/.npm/_logs/2021-09-06T10_18_18_436Z-debug.log
➜  service-mw2 git:(master) ✗ npm install npm@6 -g

removed 70 packages, changed 98 packages, and audited 438 packages in 6s

3 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
➜  service-mw2 git:(master) ✗ npm install
npm WARN deprecated [email protected]: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
npm WARN deprecated [email protected]: core-js@<3.3 is no longer maintained and not recommended for usage due to the number of issues. Because of the V8 engine whims, feature detection in old core-js versions could cause a slowdown up to 100x even if nothing is polyfilled. Please, upgrade your dependencies to the actual version of core-js.
npm WARN deprecated [email protected]: some dependency vulnerabilities fixed, support for node < 10 dropped, and newer ECMAScript syntax/features added
npm WARN deprecated [email protected]: https://github.com/lydell/resolve-url#deprecated
npm WARN deprecated [email protected]: Please see https://github.com/lydell/urix#deprecated

> [email protected] postinstall /home/xmo/code/demo/service-mw2/node_modules/core-js
> node -e "try{require('./postinstall')}catch(e){}"

Thank you for using core-js ( https://github.com/zloirock/core-js ) for polyfilling JavaScript standard library!

The project needs your help! Please consider supporting of core-js on Open Collective or Patreon:
> https://opencollective.com/core-js
> https://www.patreon.com/zloirock

Also, the author of core-js ( https://github.com/zloirock ) is looking for a good job -)


> @midwayjs/[email protected] postinstall /home/xmo/code/demo/service-mw2/node_modules/@midwayjs/cli
> node ./postinstall

[midway] auto install complete
npm notice created a lockfile as package-lock.json. You should commit this file.
npm WARN [email protected] requires a peer of @sap/hana-client@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of better-sqlite3@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of hdb-pool@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of mongodb@^3.6.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of mssql@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of oracledb@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of pg@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of pg-native@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of pg-query-stream@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of redis@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of sql.js@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of sqlite3@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of typeorm-aurora-data-api-driver@* but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @swc/core@>=1.2.50 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @swc/wasm@>=1.2.50 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of @types/jest@^27.0.0 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of babel-jest@>=27.0.0 <28 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of bufferutil@^4.0.1 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of utf-8-validate@^5.0.2 but none is installed. You must install peer dependencies yourself.
npm WARN [email protected] requires a peer of canvas@^2.5.0 but none is installed. You must install peer dependencies yourself.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: [email protected] (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

added 2263 packages from 996 contributors in 253.695s

114 packages are looking for funding
  run `npm fund` for details

此处是 npm@7 错误重现。

➜  service-mw2 git:(master) ✗ npm -v
7.22.0
➜  service-mw2 git:(master) ✗ npm install
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: [email protected]
npm ERR! Found: @types/[email protected]
npm ERR! node_modules/@types/jest
npm ERR!   dev @types/jest@"^26.0.24" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer @types/jest@"^27.0.0" from [email protected]
npm ERR! node_modules/ts-jest
npm ERR!   dev ts-jest@"^27.0.4" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See /home/xmo/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/xmo/.npm/_logs/2021-09-06T10_25_46_161Z-debug.log

虽然应该是 npm 的问题,但还是给遇到相似问题的人一些提示。如果遇到类似问题,npm install -g npm@6 版本回退即可;
另外,用yarn安装是不会产生问题的。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.