mm_os 3.3.0 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (380) hide show
  1. package/LICENSE +21 -201
  2. package/README.md +491 -99
  3. package/README_EN.md +498 -0
  4. package/adapter/adapter.js +431 -0
  5. package/adapter/custom_persistence.js +660 -0
  6. package/adapter/mqtt.js +273 -0
  7. package/adapter/socket.js +113 -0
  8. package/adapter/web.js +67 -0
  9. package/adapter/websocket.js +146 -0
  10. package/com/api/com.json +5 -0
  11. package/{core/com → com}/api/config.tpl.json +8 -8
  12. package/com/api/drive.js +708 -0
  13. package/com/api/index.js +198 -0
  14. package/com/api/oauth.js +200 -0
  15. package/com/api/script.tpl.js +32 -0
  16. package/com/cmd/README.md +11 -0
  17. package/com/cmd/com.json +5 -0
  18. package/com/cmd/config.tpl.json +122 -0
  19. package/com/cmd/drive.js +1548 -0
  20. package/com/cmd/index.js +1066 -0
  21. package/com/cmd/msg.json +48 -0
  22. package/com/cmd/nlp.js +525 -0
  23. package/com/cmd/script.tpl.js +32 -0
  24. package/com/db/com.json +5 -0
  25. package/com/db/drive.js +1999 -0
  26. package/com/db/index.js +242 -0
  27. package/com/event/com.json +5 -0
  28. package/{core/com → com}/event/config.tpl.json +8 -8
  29. package/com/event/drive.js +59 -0
  30. package/com/event/index.js +409 -0
  31. package/com/event/script.tpl.js +23 -0
  32. package/com/mqtt/com.json +5 -0
  33. package/{core/com → com}/mqtt/config.tpl.json +3 -5
  34. package/com/mqtt/drive.js +676 -0
  35. package/com/mqtt/index.js +822 -0
  36. package/com/mqtt/mm_mqtt.js +425 -0
  37. package/com/mqtt/script.tpl.js +723 -0
  38. package/com/nav/com.json +5 -0
  39. package/com/nav/config.tpl.json +84 -0
  40. package/com/nav/drive.js +702 -0
  41. package/com/nav/index.js +231 -0
  42. package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
  43. package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
  44. package/com/nav/tpl/admin_pc/page_form.vue +180 -0
  45. package/com/nav/tpl/admin_pc/page_view.vue +124 -0
  46. package/com/nav/tpl/dev_pc/page_default.vue +247 -0
  47. package/com/nav/tpl/dev_pc/page_type.vue +313 -0
  48. package/com/nav/tpl/home_pc/page_default.vue +234 -0
  49. package/com/nav/tpl/home_pc/page_form.vue +137 -0
  50. package/com/nav/tpl/home_pc/page_list.vue +234 -0
  51. package/com/nav/tpl/home_pc/page_nav.vue +221 -0
  52. package/com/nav/tpl/home_pc/page_type.vue +234 -0
  53. package/com/nav/tpl/home_pc/page_view.vue +125 -0
  54. package/com/nav/tpl/home_phone/page_channel.vue +234 -0
  55. package/com/nav/tpl/home_phone/page_default.vue +234 -0
  56. package/com/nav/tpl/home_phone/page_form.vue +137 -0
  57. package/com/nav/tpl/home_phone/page_nav.vue +237 -0
  58. package/com/nav/tpl/home_phone/page_type.vue +234 -0
  59. package/com/nav/tpl/home_phone/page_view.vue +125 -0
  60. package/com/nav/viewmodel.js +446 -0
  61. package/com/param/com.json +5 -0
  62. package/{core/com → com}/param/config.tpl.json +7 -1
  63. package/com/param/drive.js +502 -0
  64. package/com/param/index.js +155 -0
  65. package/com/param/script.tpl.js +12 -0
  66. package/com/pendant/com.json +5 -0
  67. package/{core/com/component → com/pendant}/config.tpl.json +15 -13
  68. package/com/pendant/drive.js +204 -0
  69. package/com/pendant/index.js +441 -0
  70. package/com/pendant/pendant.html +16 -0
  71. package/com/pendant/script.tpl.js +18 -0
  72. package/com/socket/com.json +5 -0
  73. package/com/socket/config.tpl.json +12 -0
  74. package/com/socket/drive.js +651 -0
  75. package/com/socket/index.js +351 -0
  76. package/com/socket/script.tpl.js +41 -0
  77. package/com/sql/com.json +5 -0
  78. package/{core/com → com}/sql/config.tpl.json +13 -9
  79. package/com/sql/drive.js +1259 -0
  80. package/com/sql/index.js +150 -0
  81. package/com/sql/script.tpl.js +47 -0
  82. package/com/static/com.json +5 -0
  83. package/{core/com → com}/static/config.tpl.json +10 -6
  84. package/com/static/drive.js +194 -0
  85. package/com/static/index.js +226 -0
  86. package/com/static/script.tpl.js +28 -0
  87. package/com/task/com.json +5 -0
  88. package/{core/com → com}/task/config.tpl.json +4 -6
  89. package/com/task/drive.js +405 -0
  90. package/com/task/index.js +148 -0
  91. package/com/task/script.tpl.js +37 -0
  92. package/com/template/com.json +5 -0
  93. package/com/template/config.tpl.json +16 -0
  94. package/com/template/drive.js +80 -0
  95. package/com/template/index.js +141 -0
  96. package/com.js +156 -0
  97. package/common/README.md +2 -0
  98. package/common/handler/msg/handler.json +22 -0
  99. package/common/handler/msg/index.js +23 -0
  100. package/common/handler/player/handler.json +22 -0
  101. package/common/handler/player/index.js +287 -0
  102. package/common/handler/user/handler.json +22 -0
  103. package/common/handler/user/index.js +23 -0
  104. package/common/middleware/web_after/index.js +29 -0
  105. package/common/middleware/web_after/middleware.json +9 -0
  106. package/common/middleware/web_base/index.js +113 -0
  107. package/common/middleware/web_base/middleware.json +19 -0
  108. package/common/middleware/web_before/index.js +33 -0
  109. package/common/middleware/web_before/middleware.json +9 -0
  110. package/common/middleware/web_cors/index.js +87 -0
  111. package/common/middleware/web_cors/middleware.json +24 -0
  112. package/common/middleware/web_error/index.js +119 -0
  113. package/common/middleware/web_error/middleware.json +18 -0
  114. package/common/middleware/web_ip/index.js +15 -0
  115. package/common/middleware/web_ip/middleware.json +14 -0
  116. package/common/middleware/web_logger/index.js +156 -0
  117. package/common/middleware/web_logger/middleware.json +14 -0
  118. package/common/middleware/web_main/index.js +24 -0
  119. package/common/middleware/web_main/middleware.json +9 -0
  120. package/common/middleware/web_static/index.js +73 -0
  121. package/common/middleware/web_static/middleware.json +54 -0
  122. package/common/middleware/web_waf/index.js +385 -0
  123. package/common/middleware/web_waf/middleware.json +13 -0
  124. package/common/model/msg/index.js +88 -0
  125. package/common/model/msg/model.json +401 -0
  126. package/common/model/player/index.js +63 -0
  127. package/common/model/player/model.json +185 -0
  128. package/common/model/user/index.js +11 -0
  129. package/common/model/user/model.json +219 -0
  130. package/core/app/config.tpl.json +67 -0
  131. package/core/app/index.js +632 -0
  132. package/core/app/script.tpl.js +52 -0
  133. package/core/channel/index.js +899 -0
  134. package/core/channel/matcher.js +585 -0
  135. package/core/com/config.tpl.json +16 -0
  136. package/core/com/index.js +74 -0
  137. package/core/com/script.tpl.js +5 -0
  138. package/core/component/component.js +42 -0
  139. package/core/component/config.tpl.json +63 -0
  140. package/core/component/index.js +273 -0
  141. package/core/component/script.tpl.js +19 -0
  142. package/core/controller/config.tpl.json +14 -0
  143. package/core/controller/index.js +373 -0
  144. package/core/controller/script.tpl.js +27 -0
  145. package/core/factory/config.tpl.json +14 -0
  146. package/core/factory/entity.js +275 -0
  147. package/core/factory/index.js +241 -0
  148. package/core/factory/script.tpl.js +16 -0
  149. package/core/game/bat/index.js +137 -0
  150. package/core/game/bat/world.js +622 -0
  151. package/core/game/config.tpl.json +16 -0
  152. package/core/game/entity_admin.js +230 -0
  153. package/core/game/index.js +186 -0
  154. package/core/handler/config.tpl.json +22 -0
  155. package/core/handler/index.js +181 -0
  156. package/core/handler/script.tpl.js +23 -0
  157. package/core/logic/config.tpl.json +14 -0
  158. package/core/logic/index.js +59 -0
  159. package/core/logic/script.tpl.js +19 -0
  160. package/core/middleware/config.tpl.json +16 -0
  161. package/core/middleware/index.js +125 -0
  162. package/core/middleware/script.tpl.js +37 -0
  163. package/core/mod/config.tpl.json +22 -0
  164. package/core/mod/index.js +130 -0
  165. package/core/mod/script.tpl.js +34 -0
  166. package/core/model/config.tpl.json +219 -0
  167. package/core/model/index.js +272 -0
  168. package/core/model/model.js +27 -0
  169. package/core/model/script.tpl.js +20 -0
  170. package/core/notifier/config.tpl.json +14 -0
  171. package/core/notifier/index.js +77 -0
  172. package/core/notifier/script.tpl.js +20 -0
  173. package/core/plugin/config.tpl.json +24 -0
  174. package/core/plugin/index.js +232 -0
  175. package/core/plugin/script.tpl.js +51 -0
  176. package/core/pusher/config.tpl.json +14 -0
  177. package/core/pusher/index.js +161 -0
  178. package/core/pusher/script.tpl.js +20 -0
  179. package/core/room/bat/index.js +170 -0
  180. package/core/room/bat/room.js +524 -0
  181. package/core/room/config.tpl.json +20 -0
  182. package/core/room/index.js +249 -0
  183. package/core/room/room.js +61 -0
  184. package/core/scene/config.tpl.json +14 -0
  185. package/core/scene/index.js +466 -0
  186. package/core/scene/loop.js +1255 -0
  187. package/core/scene/map.js +28 -0
  188. package/core/scene/script.tpl.js +22 -0
  189. package/core/sender/config.tpl.json +14 -0
  190. package/core/sender/index.js +79 -0
  191. package/core/sender/script.tpl.js +20 -0
  192. package/core/service/config.tpl.json +14 -0
  193. package/core/service/index.js +100 -0
  194. package/core/service/script.tpl.js +25 -0
  195. package/core/store/config.tpl.json +26 -0
  196. package/core/store/index.js +1755 -0
  197. package/core/store/script.tpl.js +22 -0
  198. package/core/store/sql.js +1464 -0
  199. package/core/system/config.tpl.json +18 -0
  200. package/core/system/index.js +312 -0
  201. package/core/system/script.tpl.js +77 -0
  202. package/core/view/config.tpl.json +14 -0
  203. package/core/view/index.js +91 -0
  204. package/core/view/script.tpl.js +20 -0
  205. package/core/zone/bat/index.js +725 -0
  206. package/core/zone/config.tpl.json +54 -0
  207. package/core/zone/index.js +614 -0
  208. package/core/zone/script.tpl.js +10 -0
  209. package/core/zone/zone_bat.js +136 -0
  210. package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
  211. package/index.js +17 -314
  212. package/os.js +57 -0
  213. package/package.json +60 -58
  214. package/server.js +598 -0
  215. package/README.en.md +0 -36
  216. package/conf.json +0 -3
  217. package/core/base/mqtt/index.js +0 -1107
  218. package/core/base/mqtt/lib.js +0 -40
  219. package/core/base/web/index.js +0 -243
  220. package/core/com/api/com.json +0 -4
  221. package/core/com/api/drive.js +0 -668
  222. package/core/com/api/index.js +0 -108
  223. package/core/com/api/oauth.js +0 -158
  224. package/core/com/api/script.js +0 -32
  225. package/core/com/app/README.md +0 -3
  226. package/core/com/app/com.json +0 -4
  227. package/core/com/app/config.tpl.json +0 -16
  228. package/core/com/app/drive.js +0 -309
  229. package/core/com/app/index.js +0 -211
  230. package/core/com/app/script.js +0 -155
  231. package/core/com/cmd/com.json +0 -4
  232. package/core/com/cmd/config.tpl.json +0 -66
  233. package/core/com/cmd/drive.js +0 -513
  234. package/core/com/cmd/index.js +0 -354
  235. package/core/com/cmd/old/5w2h.js +0 -54
  236. package/core/com/cmd/old/drive.js +0 -423
  237. package/core/com/cmd/script.js +0 -11
  238. package/core/com/component/README.md +0 -3
  239. package/core/com/component/com.json +0 -4
  240. package/core/com/component/component.html +0 -16
  241. package/core/com/component/drive.js +0 -197
  242. package/core/com/component/index.js +0 -312
  243. package/core/com/component/script.js +0 -18
  244. package/core/com/db/com.json +0 -4
  245. package/core/com/db/drive.js +0 -1160
  246. package/core/com/db/index.js +0 -176
  247. package/core/com/event/com.json +0 -4
  248. package/core/com/event/drive.js +0 -133
  249. package/core/com/event/index.js +0 -345
  250. package/core/com/event/script.js +0 -26
  251. package/core/com/eventer/com.js +0 -477
  252. package/core/com/eventer/com.json +0 -4
  253. package/core/com/middleware/com.js +0 -153
  254. package/core/com/middleware/com.json +0 -4
  255. package/core/com/middleware/config.tpl.json +0 -8
  256. package/core/com/middleware/script.js +0 -9
  257. package/core/com/mqtt/com.json +0 -4
  258. package/core/com/mqtt/drive.js +0 -600
  259. package/core/com/mqtt/index.js +0 -572
  260. package/core/com/mqtt/mm_mqtt.js +0 -330
  261. package/core/com/mqtt/script.js +0 -604
  262. package/core/com/msg/com.js +0 -296
  263. package/core/com/msg/com.json +0 -4
  264. package/core/com/nav/com.json +0 -4
  265. package/core/com/nav/config.tpl.json +0 -75
  266. package/core/com/nav/drive.js +0 -549
  267. package/core/com/nav/index.js +0 -182
  268. package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
  269. package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
  270. package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
  271. package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
  272. package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
  273. package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
  274. package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
  275. package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
  276. package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
  277. package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
  278. package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
  279. package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
  280. package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
  281. package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
  282. package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
  283. package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
  284. package/core/com/nav/viewmodel.js +0 -296
  285. package/core/com/param/drive.js +0 -366
  286. package/core/com/param/index.js +0 -80
  287. package/core/com/param/script.js +0 -12
  288. package/core/com/param/test.js +0 -98
  289. package/core/com/plugin/README.md +0 -3
  290. package/core/com/plugin/com.json +0 -4
  291. package/core/com/plugin/config.tpl.json +0 -26
  292. package/core/com/plugin/drive.js +0 -536
  293. package/core/com/plugin/index.js +0 -259
  294. package/core/com/plugin/script.js +0 -213
  295. package/core/com/rpc/com.json +0 -4
  296. package/core/com/rpc/drive.js +0 -160
  297. package/core/com/rpc/index.js +0 -87
  298. package/core/com/rpc/rpc.js +0 -118
  299. package/core/com/socket/com.json +0 -4
  300. package/core/com/socket/config.tpl.json +0 -14
  301. package/core/com/socket/drive.js +0 -403
  302. package/core/com/socket/index.js +0 -62
  303. package/core/com/socket/script.js +0 -42
  304. package/core/com/sql/drive.js +0 -1087
  305. package/core/com/sql/index.js +0 -83
  306. package/core/com/sql/script.js +0 -48
  307. package/core/com/static/com.json +0 -4
  308. package/core/com/static/drive.js +0 -220
  309. package/core/com/static/index.js +0 -149
  310. package/core/com/static/script.js +0 -28
  311. package/core/com/task/com.json +0 -4
  312. package/core/com/task/drive.js +0 -403
  313. package/core/com/task/index.js +0 -110
  314. package/core/com/task/script.js +0 -37
  315. package/core/com/timer/com.js +0 -217
  316. package/core/com/timer/com.json +0 -4
  317. package/core/com/tpl/com.js +0 -19
  318. package/core/com/tpl/com.json +0 -4
  319. package/lib/actions.js +0 -50
  320. package/lib/base.js +0 -361
  321. package/lib/com.js +0 -29
  322. package/lib/ref.js +0 -121
  323. package/middleware/mqtt_base/index.js +0 -10
  324. package/middleware/mqtt_base/middleware.json +0 -10
  325. package/middleware/performance/index.js +0 -151
  326. package/middleware/performance/middleware.json +0 -16
  327. package/middleware/security_audit/index.js +0 -549
  328. package/middleware/security_audit/middleware.json +0 -48
  329. package/middleware/security_headers/index.js +0 -487
  330. package/middleware/security_headers/middleware.json +0 -45
  331. package/middleware/waf/index.js +0 -348
  332. package/middleware/waf/middleware.json +0 -10
  333. package/middleware/waf_ddos/index.js +0 -520
  334. package/middleware/waf_ddos/middleware.json +0 -38
  335. package/middleware/waf_ip/index.js +0 -379
  336. package/middleware/waf_ip/middleware.json +0 -49
  337. package/middleware/waf_xss/index.js +0 -269
  338. package/middleware/waf_xss/middleware.json +0 -18
  339. package/middleware/web_after/index.js +0 -33
  340. package/middleware/web_after/middleware.json +0 -9
  341. package/middleware/web_base/index.js +0 -90
  342. package/middleware/web_base/middleware.json +0 -9
  343. package/middleware/web_before/index.js +0 -27
  344. package/middleware/web_before/middleware.json +0 -9
  345. package/middleware/web_check/index.js +0 -28
  346. package/middleware/web_check/middleware.json +0 -9
  347. package/middleware/web_main/index.js +0 -28
  348. package/middleware/web_main/middleware.json +0 -9
  349. package/middleware/web_proxy/index.js +0 -37
  350. package/middleware/web_proxy/middleware.json +0 -9
  351. package/middleware/web_render/index.js +0 -87
  352. package/middleware/web_render/middleware.json +0 -9
  353. package/middleware/web_socket/index.js +0 -34
  354. package/middleware/web_socket/middleware.json +0 -9
  355. package/middleware/web_static/index.js +0 -115
  356. package/middleware/web_static/middleware.json +0 -9
  357. /package/{core/com → com}/api/README.md +0 -0
  358. /package/{core/com → com}/db/README.md +0 -0
  359. /package/{core/com → com}/event/README.md +0 -0
  360. /package/{core/com → com}/mqtt/README.md +0 -0
  361. /package/{core/com → com}/nav/README.md +0 -0
  362. /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
  363. /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
  364. /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
  365. /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
  366. /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
  367. /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
  368. /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
  369. /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
  370. /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
  371. /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
  372. /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
  373. /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
  374. /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
  375. /package/{core/com → com}/param/README.md +0 -0
  376. /package/{core/com/cmd → com/pendant}/README.md +0 -0
  377. /package/{core/com → com}/socket/README.md +0 -0
  378. /package/{core/com → com}/sql/README.md +0 -0
  379. /package/{core/com → com}/static/README.md +0 -0
  380. /package/{core/com → com}/task/README.md +0 -0
@@ -1,18 +0,0 @@
1
- {
2
- "name": "waf_xss",
3
- "title": "XSS攻击防护中间件",
4
- "type": "web_before",
5
- "status": 1,
6
- "sort": 10,
7
- "desc": "提供全面的XSS攻击防护,包括输入过滤和安全响应头设置",
8
- "config": {
9
- "mode": "both",
10
- "query": true,
11
- "body": true,
12
- "cookie": true,
13
- "allowedTags": ["p", "span", "b", "i", "u", "strong", "em", "br"],
14
- "allowedAttributes": ["id", "class", "style"],
15
- "log": true,
16
- "block": true
17
- }
18
- }
@@ -1,33 +0,0 @@
1
- /**
2
- * web请求之后
3
- * @param {Object} server 服务
4
- * @param {Object} config 配置参数
5
- */
6
- module.exports = function(server, config) {
7
- server.use(async (ctx, next) => {
8
- try {
9
- // 先让其他中间件执行
10
- await next();
11
-
12
- // 然后执行after逻辑
13
- try {
14
- if (ctx.path !== "/favicon.ico") {
15
- await $.eventer.run('web_after', ctx, ctx.db);
16
- var event = $.event_admin('api');
17
- var ret = await event.after(ctx.path, ctx, ctx.db);
18
- if (ret) {
19
- ctx.body = ret;
20
- }
21
- }
22
- } catch (afterError) {
23
- $.log.error('web_after事件执行错误:', afterError);
24
- // 即使after事件出错,也不影响响应结果
25
- }
26
- } catch (error) {
27
- $.log.error('web_after中间件错误:', error);
28
- // 注意:这里不需要再次调用next(),因为已经在try块中调用过了
29
- }
30
- });
31
-
32
- return server;
33
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_after",
3
- "title": "web请求后",
4
- "description": "用于追加处理",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "common_before",
8
- "sort": 150
9
- }
@@ -1,90 +0,0 @@
1
- const xmlParser = require("mm_xml");
2
- const session = require('mm_session');
3
- const compress = require('koa-compress');
4
- const { koaBody } = require('koa-body');
5
- const send = require('koa-send');
6
-
7
- /**
8
- * web基础
9
- * @param {Object} server 服务
10
- * @param {Object} config 配置参数
11
- */
12
- module.exports = function(server, config) {
13
- /**
14
- * 发送文件
15
- */
16
- server.use(async (ctx, next) => {
17
- try {
18
- ctx.send = async function(src) {
19
- try {
20
- await send(ctx, src);
21
- } catch (sendError) {
22
- $.log.error('文件发送错误:', sendError);
23
- // 可以选择抛出错误让上层处理,或者静默处理
24
- throw sendError;
25
- }
26
- }
27
- await next();
28
- } catch (error) {
29
- $.log.error('web_base中间件(文件发送设置)错误:', error);
30
- // 出错时默认允许请求继续处理
31
- await next();
32
- }
33
- });
34
-
35
- // 设置session 保存时长2小时
36
- server.use(session({
37
- maxAge: $.login_period || config.maxAge || 7200
38
- }));
39
-
40
- // 使用压缩
41
- if (config.compress) {
42
- server.use(
43
- compress({
44
- filter: function(content_type) {
45
- // 只有在请求的content-type中有gzip类型,我们才会考虑压缩,因为zlib是压缩成gzip类型的
46
- return /text/i.test(content_type);
47
- },
48
- // 阀值,当数据超过1kb的时候,可以压缩
49
- threshold: 1024,
50
- // zlib是node的压缩模块
51
- flush: require('zlib').Z_SYNC_FLUSH
52
- })
53
- );
54
- }
55
-
56
- // 解析 text/xml
57
- server.use(xmlParser());
58
-
59
- var func = koaBody({
60
- jsonLimit: config.jsonLimit || '20mb',
61
- multipart: true,
62
- formidable: {
63
- // 设置上传文件大小最大限制,默认20M
64
- maxFileSize: 2000 * 1024 * 1024
65
- }
66
- });
67
-
68
- // 解析 application/json、application/x-www-form-urlencoded、text/plain
69
- // 接收主体
70
- server.use(async (ctx, next) => {
71
- try {
72
- if (!ctx.request.body) {
73
- try {
74
- await func(ctx, next);
75
- } catch (parseError) {
76
- $.log.error('请求体解析错误:', parseError);
77
- // 解析错误时,确保请求继续处理
78
- await next();
79
- }
80
- } else {
81
- await next();
82
- }
83
- } catch (error) {
84
- $.log.error('web_base中间件(请求体解析)错误:', error);
85
- // 出错时默认允许请求继续处理
86
- await next();
87
- }
88
- });
89
- return server;
90
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_base",
3
- "title": "web基本功能",
4
- "description": "用于网站常规功能",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "common_before",
8
- "sort": 70
9
- }
@@ -1,27 +0,0 @@
1
- /**
2
- * web请求之前
3
- * @param {Object} server 服务
4
- * @param {Object} config 配置参数
5
- */
6
- module.exports = function(server, config) {
7
- // 使用路由(主要)
8
- server.use(async (ctx, next) => {
9
- if (!ctx.db) {
10
- ctx.db = {
11
- ret: null
12
- };
13
- }
14
- if (ctx.path !== "/favicon.ico") {
15
- await $.eventer.run('web_before', ctx, ctx.db);
16
- var event = $.event_admin('api');
17
- var ret = await event.before(ctx.path, ctx, ctx.db);
18
- // console.log("before阶段", ret);
19
- if (ret) {
20
- ctx.body = ret;
21
- }
22
- }
23
- await next();
24
- });
25
-
26
- return server;
27
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_before",
3
- "title": "web请求前",
4
- "description": "用于",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "common_before",
8
- "sort": 80
9
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * web验证
3
- * @param {Object} server 服务
4
- * @param {Object} config 配置参数
5
- */
6
- module.exports = function(server, config) {
7
- // 使用路由(主要)
8
- server.use(async (ctx, next) => {
9
- try {
10
- if (ctx.path !== "/favicon.ico") {
11
- await $.eventer.run('web_check', ctx, ctx.db);
12
- var event = $.event_admin('api');
13
- var ret = await event.check(ctx.path, ctx, ctx.db);
14
- // console.log("check阶段", ret);
15
- if (ret) {
16
- ctx.body = ret;
17
- }
18
- }
19
- await next();
20
- } catch (error) {
21
- $.log.error('web_check中间件错误:', error);
22
- // 确保请求可以继续处理
23
- await next();
24
- }
25
- });
26
-
27
- return server;
28
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_check",
3
- "title": "web请求验证",
4
- "description": "用于验证请求,拦截不符合调条件的请求",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "common_before",
8
- "sort": 90
9
- }
@@ -1,28 +0,0 @@
1
- /**
2
- * web请求
3
- * @param {Object} server 服务
4
- * @param {Object} config 配置参数
5
- */
6
- module.exports = function(server, config) {
7
- // 使用路由(主要)
8
- server.use(async (ctx, next) => {
9
- try {
10
- if (ctx.path !== "/favicon.ico") {
11
- await $.eventer.run('web_main', ctx, ctx.db);
12
- var event = $.event_admin('api');
13
- var ret = await event.main(ctx.path, ctx, ctx.db);
14
- // console.log("main阶段", ret);
15
- if (ret) {
16
- ctx.body = ret;
17
- }
18
- }
19
- await next();
20
- } catch (error) {
21
- $.log.error('web_main中间件错误:', error);
22
- // 确保请求可以继续处理
23
- await next();
24
- }
25
- });
26
-
27
- return server;
28
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_main",
3
- "title": "web请求主要",
4
- "description": "用于处理主要请求",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "common_before",
8
- "sort": 100
9
- }
@@ -1,37 +0,0 @@
1
- const {
2
- proxy,
3
- proxyTo,
4
- isMatch
5
- } = require('mm_koa_proxy');
6
-
7
- /**
8
- * 代理请求
9
- * @param {Object} server 服务
10
- * @param {Object} config 配置参数
11
- */
12
- module.exports = function(server, config) {
13
- if (config && config.proxy) {
14
- var options = config.proxy;
15
- if (options.targets) {
16
- server.use(async (ctx, next) => {
17
- try {
18
- // 先设置用户信息头
19
- if (ctx.session && ctx.session.user) {
20
- ctx.request.header['user_id'] = ctx.session.user.user_id;
21
- }
22
- // 创建一个代理处理器
23
- const proxyHandler = proxy(options, function(op, ctxProxy, nextProxy) {
24
- return nextProxy();
25
- });
26
- // 执行代理
27
- await proxyHandler(ctx, next);
28
- } catch (error) {
29
- $.log.error('web_proxy中间件错误:', error);
30
- // 出错时默认允许请求继续处理
31
- await next();
32
- }
33
- });
34
- }
35
- }
36
- return server;
37
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_proxy",
3
- "title": "web代理服务",
4
- "description": "用于将特定路由转发到别的服务端上做处理",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "worker",
8
- "sort": 110
9
- }
@@ -1,87 +0,0 @@
1
- /**
2
- * 调用函数
3
- * @param {Object} ret 设置响应结果
4
- * @param {Object} res 响应器
5
- * @param {String} t 请求类型
6
- * @return {String} 处理后的响应结果
7
- */
8
- function render_body(ret, res, t) {
9
- var type;
10
- if (res.type) {
11
- type = res.type;
12
- }
13
- var tp = typeof(ret);
14
- if (tp === "object") {
15
- if (!type) {
16
- /// 设置响应头
17
- if (t.indexOf('xml') !== -1) {
18
- type = t;
19
- } else {
20
- type = "application/json; charset=utf-8";
21
- }
22
- res.type = type;
23
- } else {
24
- if (type.indexOf('json') !== -1) {
25
- type = "application/json; charset=utf-8";
26
- } else if (type.indexOf('html') !== -1) {
27
- type = "text/html";
28
- } else if (type.indexOf('xml') !== -1) {
29
- type = "text/xml; charset=utf-8";
30
- } else {
31
- type = "text/plain; charset=utf-8";
32
- }
33
- res.type = type;
34
- }
35
-
36
- if (type.indexOf('/xml') !== -1) {
37
- return $.toXml(ret);
38
- } else {
39
- return JSON.stringify(ret);
40
- }
41
- } else if (tp === "string") {
42
- ret = ret.trim();
43
- if (!type) {
44
- if (ret.startWith('{') && ret.endWith('}')) {
45
- res.type = "application/json; charset=utf-8";
46
- } else if (ret.startWith('[') && ret.endWith(']')) {
47
- res.type = "application/json; charset=utf-8";
48
- } else if (ret.endWith("</html>")) {
49
- res.type = "text/html";
50
- } else {
51
- res.type = "text/plain; charset=utf-8";
52
- }
53
- }
54
- }
55
- return ret;
56
- };
57
-
58
- /**
59
- * web渲染
60
- * @param {Object} server 服务
61
- * @param {Object} config 配置参数
62
- */
63
- module.exports = function(server, config) {
64
- // 使用路由(主要)
65
- server.use(async (ctx, next) => {
66
- try {
67
- if (ctx.path !== "/favicon.ico") {
68
- await $.eventer.run('web_render', ctx, ctx.db);
69
- var event = $.event_admin('api');
70
- var ret = await event.render(ctx.path, ctx, ctx.db);
71
- if (!ctx.body && ret) {
72
- ctx.body = ret;
73
- }
74
- if (ctx.body) {
75
- ctx.body = render_body(ctx.body, ctx.response, ctx.request.type);
76
- }
77
- }
78
- await next();
79
- } catch (error) {
80
- $.log.error('web_render中间件错误:', error);
81
- // 确保请求可以继续处理
82
- await next();
83
- }
84
- });
85
-
86
- return server;
87
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_render",
3
- "title": "web请求渲染",
4
- "description": "用于响应请求是加工响应的数据",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "common_before",
8
- "sort": 120
9
- }
@@ -1,34 +0,0 @@
1
- const websocket = require('koa-websocket');
2
-
3
- /**
4
- * web socket请求
5
- * @param {Object} server 服务
6
- */
7
- module.exports = function(server, config) {
8
- // 引入web socket通讯
9
- server = websocket(server);
10
- if (config.socket && $.Socket) {
11
- // console.log("已启动websocket服务!");
12
- //使用 websocket 服务
13
- $.socket = new $.Socket();
14
- $.socket.update();
15
- server.ws.use(async (ctx, next) => {
16
- try {
17
- // 确保$.socket.run是异步执行的
18
- await Promise.resolve($.socket.run(ctx, next));
19
- } catch (error) {
20
- $.log.error('web_socket中间件错误:', error);
21
- // WebSocket连接错误时,尝试关闭连接以避免资源泄漏
22
- try {
23
- if (ctx.websocket && ctx.websocket.readyState === ctx.websocket.OPEN) {
24
- ctx.websocket.close(1011, 'Internal server error');
25
- }
26
- } catch (closeError) {
27
- // 忽略关闭连接时的错误
28
- }
29
- }
30
- });
31
- }
32
-
33
- return server;
34
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_socket",
3
- "title": "websocket通讯",
4
- "description": "用于即时通讯",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "master",
8
- "sort": 130
9
- }
@@ -1,115 +0,0 @@
1
- /**
2
- * 增强的静态资源处理中间件
3
- * 提供缓存控制、压缩、预加载等性能优化功能
4
- */
5
- const statics = require('mm_statics');
6
- const compress = require('koa-compress');
7
-
8
- /**
9
- * 静态资源请求
10
- * @param {Object} server 服务
11
- * @param {Object} config 配置参数
12
- */
13
- module.exports = function(server, config) {
14
- // 配置默认值
15
- const cg = Object.assign({
16
- static: true,
17
- maxAge: 365 * 24 * 60 * 60, // 默认缓存一年
18
- compress: true,
19
- compressThreshold: 1024, // 大于1KB的文件才压缩
20
- enablePreload: true, // 启用预加载提示
21
- staticPaths: [] // 多路径配置
22
- }, config);
23
-
24
- // 处理静态文件
25
- if (cg.static) {
26
- // 添加压缩中间件
27
- if (cg.compress && typeof compress === 'function') {
28
- server.use(compress({
29
- filter: function(content_type) {
30
- return /text|json|javascript|css|xml/.test(content_type);
31
- },
32
- threshold: cg.compressThreshold,
33
- gzip: { flush: require('zlib').constants.Z_SYNC_FLUSH },
34
- brotli: { flush: require('zlib').constants.BROTLI_OPERATION_FLUSH }
35
- }));
36
- }
37
-
38
- // 主静态路径处理
39
- if (config.static_path) {
40
- // 为mm_statics添加错误处理包装器
41
- const staticHandler = statics(
42
- config.static_path.fullname(), {
43
- maxAge: cg.maxAge,
44
- gzip: cg.compress,
45
- brotli: cg.compress
46
- });
47
-
48
- server.use(async (ctx, next) => {
49
- // 预加载提示处理
50
- if (cg.enablePreload && ctx.path === '/') {
51
- ctx.append('Link', '</static/css/main.css>; rel=preload; as=style');
52
- ctx.append('Link', '</static/js/main.js>; rel=preload; as=script');
53
- }
54
- try {
55
- await staticHandler(ctx, next);
56
- } catch (staticError) {
57
- if (staticError.code !== 'ENOENT') { // 忽略文件不存在的错误
58
- $.log.error('静态资源服务错误:', staticError);
59
- }
60
- // 出错时继续处理请求
61
- await next();
62
- }
63
- });
64
- }
65
-
66
- // 多路径静态文件处理
67
- if (Array.isArray(cg.staticPaths) && cg.staticPaths.length > 0) {
68
- cg.staticPaths.forEach((pathConfig, index) => {
69
- try {
70
- const staticPathHandler = statics(
71
- pathConfig.path.fullname(),
72
- Object.assign({
73
- maxAge: cg.maxAge,
74
- gzip: cg.compress,
75
- brotli: cg.compress
76
- }, pathConfig.options || {})
77
- );
78
-
79
- server.use(async (ctx, next) => {
80
- try {
81
- await staticPathHandler(ctx, next);
82
- } catch (e) {
83
- if (e.code !== 'ENOENT') {
84
- $.log.error(`静态资源路径[${pathConfig.path}]服务错误:`, e);
85
- }
86
- await next();
87
- }
88
- });
89
- } catch (e) {
90
- $.log.error(`静态资源多路径配置错误[${index}]:`, e);
91
- }
92
- });
93
- }
94
-
95
- // 使用多路径静态文件处理器(保留原有功能)
96
- if ($.Static) {
97
- const Static = $.Static;
98
- $.static = new Static();
99
- $.static.update();
100
-
101
- // 为$.static.run添加错误处理包装器
102
- server.use(async (ctx, next) => {
103
- try {
104
- // 确保静态文件处理器是异步执行的
105
- await Promise.resolve($.static.run(ctx, next));
106
- } catch (staticRunError) {
107
- $.log.error('多路径静态资源服务错误:', staticRunError);
108
- // 出错时继续处理请求
109
- await next();
110
- }
111
- });
112
- }
113
- }
114
- return server;
115
- };
@@ -1,9 +0,0 @@
1
- {
2
- "name": "web_static",
3
- "title": "web静态文件处理",
4
- "description": "用于处理静态文件",
5
- "version": "1.0",
6
- "type": "web",
7
- "process_type": "worker",
8
- "sort": 140
9
- }
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes