dragonwong / blog

a blog based on github page
dragonwong.github.io/blog/
9 stars 4 forks source link

eggjs 使用实录 #22

Open dragonwong opened 6 years ago

dragonwong commented 6 years ago

感觉大阿里的这个框架还是不错的!记录下使用的心得。

  1. 执行 npm start 命令环境是会默认设置为 prod

  2. prod 环境下运行日志是不会落到文件里的,需要配置 disableConsoleAfterReady 开启。参考:https://github.com/eggjs/egg/issues/1593

  3. prod 环境下日志存储路径为 /home/${user}/logs/${app-name}/。参考:日志路径

  4. 为充分的利用 CPU 资源,npm start 默认会创建和 CPU 核数相当的 app worker 数,如果有业务逻辑写在文件入口处(当然这是错误的写法),会导致多次执行。启动命令后加上 --workers=1 可以设置 worker 数量。当然最好还是把执行一次的逻辑写进 agent 里。npm run dev 只启一个 worker。参考:启动命令

  5. 官方 API 文档:https://eggjs.org/api/

dragonwong commented 6 years ago

入了阿里的坑,eggjs + antd pro,你也可以当全栈工程师!

就是 antd pro 的网站都被墙了,自备梯子。

dragonwong commented 5 years ago

关于数据库日期字段的读写操作

对于 timestamp 类型的字段来说,js 在写入时只能以 yyyy-MM-dd hh:mm:ss.S 的字符串形式,但 js 获取时又变成了 Date 类型,是不是很奇怪鸭~

dragonwong commented 5 years ago

关于多服务运行的坑

package.json 启动和停止命令里会通过 title 字段指定服务名称,比如

"start": "egg-scripts start --daemon --title=egg-server-xxx,
"stop": "egg-scripts stop --title=egg-server-xxx",

其中停止命令里是使用的 includes 命令进行筛选,于是如果停止 egg-server-xxx 会把 egg-server-xxx-yyy 也一并停止了。

为避免这个问题,只能在命名上做约束。