fsd-nodejs / service-mw2 Goto Github PK
View Code? Open in Web Editor NEWNode.js 全栈开发之 Midway.js 最佳实践
License: MIT License
Node.js 全栈开发之 Midway.js 最佳实践
License: MIT License
项目未做任何修改,
运行环境
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 。
目录结构和midway(v2)文档里的不一致,很多文档里推荐放在src目录下的都放在了app目录下下,如果用eggjs作为上层框架的话更推荐哪种目录结构啊
目前已增加容器化启动
但是阿里云的serverless 配置还是有问题
base model中id为string的意义是什么?数据库id不是基本都是int或者bugint类型?这里数据模型id也应该是number才是啊,为啥是string。求科普一下
我是一个前端,学习代码可以但是代码写好以后部署就遇到了麻烦
port: process.env.MYSQL_HOST || 3306 应该写成
port: process.env.MYSQL_PORT || 3306
配套前端项目[https://github.com/fsd-nodejs/pc]请求的接口跟此项目提供的接口对应不上,因此前端项目请求接口总是失败,请问该怎么解决呢?
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"
这里建议把 decode(...)
换成 verify(...)
,因为可能出现小白错误理解的情况,而且 auth 的场景也确实应该使用 verify 😅。
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
警告:当令牌来自不受信任的来源(例如用户输入或外部请求)时,应将返回的解码负载视为任何其他用户输入; 请确保进行消毒并仅使用预期的属性(纯机翻 😁)
运行 npm run dev; 报错数据库连不上
Host 'host.docker.internal' is not allowed to connect to this MySQL server
我找到一个问题地址,不太理解
我安装了docker desk
测试了一下,dto不符合入参要求,或者controller里的MyError抛错都可以被全局的error-handler捕获到,不知道为啥自定义的函数里,没有被捕获到?自定义的函数主要也是在controller里调用的,比如在helper里定义了一个公共函数,相关校验没有通过,使用类似
const record = xxx;
assert(record, new MyError('您没有相关的操作权限', 403));
return true;
预期效果:如果record为空,MyError被捕获到,并中断处理流程
实际效果:仅在后台报了unhandledRejectionError,未中断处理流程,返回给前端的是200
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安装是不会产生问题的。
3.x 的改动比较大,将新建一个新的分支处理
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.