如果你接手了一个你不熟悉的项目,是基于Egg.js框架编写的,其中使用了很多挂载在上下文ctx的方法,而你又找不到这个方法源码位置,那么可以通过调用方法,传一些不符号参数要求的数据进入,使其报错,拿到调用栈与文件位置。
await ctx.compare(payload.password, user.password);
// 改为
await ctx.compare(123);
2024-11-25 13:07:40,888 ERROR 158760 [egg-bcrypt] Error: Illegal arguments: string, undefined
at _async (C:\Users\wujingquan\workspace\parking\node_modules\bcryptjs\dist\bcrypt.js:286:46)
at C:\Users\wujingquan\workspace\parking\node_modules\bcryptjs\dist\bcrypt.js:307:17
at new Promise (<anonymous>)
at Object.bcrypt.compare (C:\Users\wujingquan\workspace\parking\node_modules\bcryptjs\dist\bcrypt.js:306:20)
at Object.compare (C:\Users\wujingquan\workspace\parking\node_modules\egg-bcrypt\app\extend\context.js:13:8)
at AccessController.login (C:\Users\wujingquan\workspace\parking\app\controller\access.js:54:35)
at processTicksAndRejections (internal/process/task_queues.js:95:5)
at async errorHandler (C:\Users\wujingquan\workspace\parking\app\middleware\error_handler.js:5:7)
at async C:\Users\wujingquan\workspace\parking\node_modules\egg-development\app\middleware\egg_loader_trace.js:9:50
at async xframe (C:\Users\wujingquan\workspace\parking\node_modules\egg-security\lib\middlewares\xframe.js:7:5)
at async xssProtection (C:\Users\wujingquan\workspace\parking\node_modules\egg-security\lib\middlewares\xssProtection.js:7:5)
at async nosniff (C:\Users\wujingquan\workspace\parking\node_modules\egg-security\lib\middlewares\nosniff.js:8:5)
at async noopen (C:\Users\wujingquan\workspace\parking\node_modules\egg-security\lib\middlewares\noopen.js:8:5)
at async session (C:\Users\wujingquan\workspace\parking\node_modules\koa-session\index.js:41:7)
at async bodyParser (C:\Users\wujingquan\workspace\parking\node_modules\koa-bodyparser\index.js:78:5)
at async C:\Users\wujingquan\workspace\parking\node_modules\koa-static-cache\index.js:39:63
Egg.js环境配置、环境变量
npm run dev
是开发环境,默认加载的是config.default.js
和config.local.js
,npm run start
是生产环境,所以默认加载的是config.default.js
和config.prod.js
正文完
发表至: 分享
2024-11-25