app.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. 'use strict';
  2. // app.js
  3. module.exports = app => {
  4. // 开始前执行
  5. app.beforeStart(async () => {
  6. // 此处是你原来的逻辑代码
  7. app.logger.info('启动成功20201010');
  8. // TODO 84个语句查询 平均每个查询慢的3-5min 快的1s 均值1min 清洗一次 2小时
  9. // 考虑所有的下拉都对应一个接口
  10. // 1.5-6上报类型
  11. // 2.br7里面的 驾驶模式等
  12. // 3.11里的远控功能 + app功能(后台处理好一定有名字)
  13. // 4.br22里的下拉
  14. // 5.iviBehavior出现查不出来的情况
  15. // 6.车的人 一定在全量人里得有 在线记录里得人在全量人里得有 || 车行为对应的车必须在全量车里有
  16. // 车娱乐行为对应车行为对应全量车有 app功能的使用人对应全量人有 车辆上报对应车 转换车主对应全量人 tbox对应全车 在线车对应全车
  17. //
  18. });
  19. // 准备好执行
  20. app.ready(async () => {
  21. // 举例,获取数据库图片域名,放到缓存,便于使用
  22. });
  23. // 关闭前执行
  24. app.beforeClose(async () => {
  25. // this.app.logger 应用级别的日志记录,如记录启动阶段的一些数据信息,记录一些业务上与请求无关的信息
  26. // this.app.coreLogger 开发应用时都不应该通过 CoreLogger 打印日志,而框架和插件则需要通过它来打印应用级别的日志,这样可以更清晰的区分应用和框架打印的日志,通过 CoreLogger 打印的日志会放到和 Logger 不同的文件中
  27. // this.ctx.logger 请求相关的,它打印的日志都会在前面带上一些当前请求相关的信息(如 [$userId/$ip/$traceId/${cost}ms $method $url])
  28. // this.ctx.coreLogger 和 Context Logger 的区别是一般只有插件和框架会通过它来记录日志
  29. // Controller Logger & Service Logger this.logger 本质上就是一个 Context Logger,会额外的加上文件路径
  30. // 同时 Context 上也挂载了 Request 和 Response 两个对象。和 Express 类似,
  31. // 这两个对象都提供了大量的便捷方法辅助开发,例如
  32. //
  33. // get request.query
  34. // get request.hostname
  35. // set response.body
  36. // set response.status
  37. // 参数校验 validate接入egg
  38. // this.ctx.curl 相当于ajax
  39. });
  40. // 监听
  41. // app.once('server', server => {
  42. // // websocket
  43. // });
  44. // app.on('error', (err, ctx) => {
  45. // // report error
  46. // });
  47. // app.on('request', ctx => {
  48. // // log receive request
  49. // });
  50. // app.on('response', ctx => {
  51. // // ctx.starttime is set by framework
  52. // const used = Date.now() - ctx.starttime;
  53. // // log total cost
  54. // });
  55. };