mm_os 1.3.4 → 1.3.6
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.
- package/README.en.md +36 -0
- package/README.md +25 -166
- package/conf.json +3 -0
- package/core/base/index.js +29 -0
- package/core/base/mqtt/index.js +268 -0
- package/core/base/mqtt/lib.js +40 -0
- package/core/base/web/index.js +110 -0
- package/core/com/api/com.json +4 -0
- package/{bin → core}/com/api/config.tpl.json +9 -7
- package/{bin → core}/com/api/drive.js +239 -64
- package/{bin → core}/com/api/index.js +8 -9
- package/{bin → core}/com/api/oauth.js +23 -14
- package/core/com/api/script.js +32 -0
- package/core/com/db/com.json +4 -0
- package/{bin → core}/com/db/drive.js +99 -65
- package/{bin → core}/com/db/index.js +2 -2
- package/core/com/event/com.json +4 -0
- package/{bin → core}/com/event/config.tpl.json +2 -2
- package/core/com/event/drive.js +125 -0
- package/{bin → core}/com/event/index.js +5 -10
- package/core/com/event/script.js +26 -0
- package/core/com/eventer/com.js +450 -0
- package/core/com/eventer/com.json +4 -0
- package/core/com/middleware/com.js +128 -0
- package/core/com/middleware/com.json +4 -0
- package/core/com/middleware/config.tpl.json +8 -0
- package/core/com/middleware/script.js +9 -0
- package/core/com/mqtt/com.json +4 -0
- package/core/com/mqtt/config.tpl.json +12 -0
- package/core/com/mqtt/drive.js +139 -0
- package/core/com/mqtt/index.js +138 -0
- package/core/com/mqtt/script.js +33 -0
- package/core/com/msg/com.js +296 -0
- package/core/com/msg/com.json +4 -0
- package/{bin → core}/com/nav/drive.js +42 -17
- package/{bin → core}/com/nav/index.js +4 -4
- package/core/com/nav/tpl/admin_pc/page_channel.vue +299 -0
- package/core/com/nav/tpl/admin_pc/page_config.vue +279 -0
- package/core/com/nav/tpl/admin_pc/page_config_form.vue +194 -0
- package/core/com/nav/tpl/admin_pc/page_default.vue +287 -0
- package/core/com/nav/tpl/admin_pc/page_form.vue +180 -0
- package/core/com/nav/tpl/admin_pc/page_lang.vue +265 -0
- package/core/com/nav/tpl/admin_pc/page_nav.vue +313 -0
- package/core/com/nav/tpl/admin_pc/page_table.vue +285 -0
- package/core/com/nav/tpl/admin_pc/page_type.vue +313 -0
- package/core/com/nav/tpl/dev_pc/page_channel.vue +253 -0
- package/core/com/nav/tpl/dev_pc/page_config.vue +253 -0
- package/core/com/nav/tpl/dev_pc/page_default.vue +247 -0
- package/core/com/nav/tpl/dev_pc/page_form.vue +162 -0
- package/core/com/nav/tpl/dev_pc/page_nav.vue +253 -0
- package/core/com/nav/tpl/dev_pc/page_table.vue +247 -0
- package/core/com/nav/tpl/dev_pc/page_type.vue +253 -0
- package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_channel.vue +231 -231
- package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_default.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_pc/page_form.vue +9 -9
- package/{bin → core}/com/nav/tpl/home_pc/page_list.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_pc/page_nav.vue +221 -221
- package/{bin/com/nav/tpl/home_phone → core/com/nav/tpl/home_pc}/page_type.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_pc/page_view.vue +8 -8
- package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_channel.vue +231 -231
- package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_default.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_phone/page_form.vue +9 -9
- package/{bin → core}/com/nav/tpl/home_phone/page_list.vue +231 -231
- package/{bin/com/nav/tpl/admin_pc → core/com/nav/tpl/home_phone}/page_nav.vue +236 -220
- package/{bin/com/nav/tpl/home_pc → core/com/nav/tpl/home_phone}/page_type.vue +231 -231
- package/{bin → core}/com/nav/tpl/home_phone/page_view.vue +8 -8
- package/core/com/nav/viewmodel.js +296 -0
- package/{bin → core}/com/param/config.tpl.json +24 -0
- package/{bin → core}/com/param/drive.js +47 -15
- package/core/com/plugin/com.json +4 -0
- package/core/com/plugin/config.tpl.json +20 -0
- package/{bin → core}/com/plugin/drive.js +5 -8
- package/{bin → core}/com/plugin/index.js +11 -56
- package/core/com/socket/README.md +47 -0
- package/core/com/socket/com.json +4 -0
- package/core/com/socket/config.tpl.json +14 -0
- package/{bin → core}/com/socket/drive.js +74 -51
- package/{bin → core}/com/socket/index.js +4 -2
- package/{bin → core}/com/socket/script.js +8 -6
- package/core/com/sql/config.tpl.json +70 -0
- package/{bin → core}/com/sql/drive.js +281 -58
- package/core/com/static/com.json +4 -0
- package/core/com/static/config.tpl.json +20 -0
- package/{bin → core}/com/static/drive.js +6 -4
- package/{bin → core}/com/static/index.js +5 -1
- package/core/com/task/com.json +4 -0
- package/core/com/task/config.tpl.json +24 -0
- package/core/com/task/drive.js +374 -0
- package/{bin → core}/com/task/index.js +14 -20
- package/core/com/task/script.js +37 -0
- package/core/com/timer/com.js +217 -0
- package/core/com/timer/com.json +4 -0
- package/core/com/tpl/com.js +19 -0
- package/core/com/tpl/com.json +4 -0
- package/index.js +161 -740
- package/lib/actions.js +50 -0
- package/lib/app.js +73 -0
- package/lib/base.js +355 -0
- package/lib/com.js +31 -0
- package/lib/game.js +31 -0
- package/lib/ref.js +121 -0
- package/middleware/cors/index.js +57 -0
- package/middleware/cors/middleware.json +7 -0
- package/middleware/mqtt_base/index.js +10 -0
- package/middleware/mqtt_base/middleware.json +8 -0
- package/{waf.js → middleware/waf/index.js} +12 -2
- package/middleware/waf/middleware.json +9 -0
- package/middleware/web_base/index.js +67 -0
- package/middleware/web_base/middleware.json +9 -0
- package/middleware/web_event/index.js +411 -0
- package/middleware/web_event/middleware.json +10 -0
- package/middleware/web_proxy/index.js +24 -0
- package/middleware/web_proxy/middleware.json +9 -0
- package/middleware/web_router/index.js +33 -0
- package/middleware/web_router/middleware.json +10 -0
- package/middleware/web_socket/index.js +21 -0
- package/middleware/web_socket/middleware.json +9 -0
- package/middleware/web_static/index.js +26 -0
- package/middleware/web_static/middleware.json +9 -0
- package/nodemon.json +12 -2
- package/package.json +56 -66
- package/.gitattributes +0 -5
- package/bin/com/README.md +0 -2
- package/bin/com/api/script.js +0 -14
- package/bin/com/cmd/README.md +0 -3
- package/bin/com/cmd/config.tpl.json +0 -41
- package/bin/com/cmd/drive.js +0 -512
- package/bin/com/cmd/index.js +0 -213
- package/bin/com/cmd/old/5w2h.js +0 -54
- package/bin/com/cmd/old/drive.js +0 -423
- package/bin/com/cmd/script.js +0 -11
- package/bin/com/event/drive.js +0 -69
- package/bin/com/event/script.js +0 -12
- package/bin/com/nav/tpl/admin_pc/page_channel.vue +0 -234
- package/bin/com/nav/tpl/admin_pc/page_default.vue +0 -236
- package/bin/com/nav/tpl/admin_pc/page_form.vue +0 -152
- package/bin/com/nav/tpl/admin_pc/page_table.vue +0 -236
- package/bin/com/nav/tpl/admin_pc/page_type.vue +0 -234
- package/bin/com/nav/tpl/home_phone/page_nav.vue +0 -221
- package/bin/com/nav/viewmodel.js +0 -161
- package/bin/com/plugin/config.tpl.json +0 -11
- package/bin/com/socket/config.tpl.json +0 -8
- package/bin/com/sql/config.tpl.json +0 -34
- package/bin/com/static/config.tpl.json +0 -11
- package/bin/com/task/config.tpl.json +0 -13
- package/bin/com/task/drive.js +0 -288
- package/bin/com/task/script.js +0 -38
- package/bin/com.js +0 -74
- package/bin/mm.conf +0 -48
- package/bin/static/404.html +0 -52
- package/bin/static/README.md +0 -1
- package/bin/static/css/font-awesome.min.css +0 -7
- package/bin/static/css/mm_base.css +0 -220
- package/bin/static/css/mm_common.css +0 -518
- package/bin/static/css/mm_component.css +0 -307
- package/bin/static/css/mm_expand.css +0 -634
- package/bin/static/css/mm_theme.css +0 -291
- package/bin/static/css/new_file.css +0 -79
- package/bin/static/css/swiper.min.css +0 -12
- package/bin/static/favicon.ico +0 -0
- package/bin/static/font/FontAwesome.otf +0 -0
- package/bin/static/font/HelveticaNeue.eot +0 -0
- package/bin/static/font/HelveticaNeue.otf +0 -0
- package/bin/static/font/HelveticaNeue.svg +0 -1273
- package/bin/static/font/HelveticaNeue.woff +0 -0
- package/bin/static/font/HelveticaNeue.woff2 +0 -0
- package/bin/static/font/fontawesome-webfont.eot +0 -0
- package/bin/static/font/fontawesome-webfont.svg +0 -2671
- package/bin/static/font/fontawesome-webfont.ttf +0 -0
- package/bin/static/font/fontawesome-webfont.woff +0 -0
- package/bin/static/font/fontawesome-webfont.woff2 +0 -0
- package/bin/static/h5.html +0 -325
- package/bin/static/highlight/highlight.pack.js +0 -2
- package/bin/static/highlight/styles/a11y-dark.css +0 -99
- package/bin/static/highlight/styles/a11y-light.css +0 -99
- package/bin/static/highlight/styles/agate.css +0 -108
- package/bin/static/highlight/styles/an-old-hope.css +0 -89
- package/bin/static/highlight/styles/androidstudio.css +0 -66
- package/bin/static/highlight/styles/arduino-light.css +0 -88
- package/bin/static/highlight/styles/arta.css +0 -73
- package/bin/static/highlight/styles/ascetic.css +0 -45
- package/bin/static/highlight/styles/atelier-cave-dark.css +0 -83
- package/bin/static/highlight/styles/atelier-cave-light.css +0 -85
- package/bin/static/highlight/styles/atelier-dune-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-dune-light.css +0 -69
- package/bin/static/highlight/styles/atelier-estuary-dark.css +0 -84
- package/bin/static/highlight/styles/atelier-estuary-light.css +0 -84
- package/bin/static/highlight/styles/atelier-forest-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-forest-light.css +0 -69
- package/bin/static/highlight/styles/atelier-heath-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-heath-light.css +0 -69
- package/bin/static/highlight/styles/atelier-lakeside-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-lakeside-light.css +0 -69
- package/bin/static/highlight/styles/atelier-plateau-dark.css +0 -84
- package/bin/static/highlight/styles/atelier-plateau-light.css +0 -84
- package/bin/static/highlight/styles/atelier-savanna-dark.css +0 -84
- package/bin/static/highlight/styles/atelier-savanna-light.css +0 -84
- package/bin/static/highlight/styles/atelier-seaside-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-seaside-light.css +0 -69
- package/bin/static/highlight/styles/atelier-sulphurpool-dark.css +0 -69
- package/bin/static/highlight/styles/atelier-sulphurpool-light.css +0 -69
- package/bin/static/highlight/styles/atom-one-dark-reasonable.css +0 -77
- package/bin/static/highlight/styles/atom-one-dark.css +0 -96
- package/bin/static/highlight/styles/atom-one-light.css +0 -96
- package/bin/static/highlight/styles/brown-paper.css +0 -64
- package/bin/static/highlight/styles/brown-papersq.png +0 -0
- package/bin/static/highlight/styles/codepen-embed.css +0 -60
- package/bin/static/highlight/styles/color-brewer.css +0 -71
- package/bin/static/highlight/styles/darcula.css +0 -77
- package/bin/static/highlight/styles/dark.css +0 -63
- package/bin/static/highlight/styles/darkula.css +0 -6
- package/bin/static/highlight/styles/default.css +0 -99
- package/bin/static/highlight/styles/docco.css +0 -97
- package/bin/static/highlight/styles/dracula.css +0 -76
- package/bin/static/highlight/styles/far.css +0 -71
- package/bin/static/highlight/styles/foundation.css +0 -88
- package/bin/static/highlight/styles/github-gist.css +0 -79
- package/bin/static/highlight/styles/github.css +0 -99
- package/bin/static/highlight/styles/gml.css +0 -78
- package/bin/static/highlight/styles/googlecode.css +0 -89
- package/bin/static/highlight/styles/grayscale.css +0 -101
- package/bin/static/highlight/styles/gruvbox-dark.css +0 -108
- package/bin/static/highlight/styles/gruvbox-light.css +0 -108
- package/bin/static/highlight/styles/hopscotch.css +0 -83
- package/bin/static/highlight/styles/hybrid.css +0 -102
- package/bin/static/highlight/styles/idea.css +0 -97
- package/bin/static/highlight/styles/ir-black.css +0 -73
- package/bin/static/highlight/styles/isbl-editor-dark.css +0 -112
- package/bin/static/highlight/styles/isbl-editor-light.css +0 -112
- package/bin/static/highlight/styles/kimbie.dark.css +0 -74
- package/bin/static/highlight/styles/kimbie.light.css +0 -74
- package/bin/static/highlight/styles/lightfair.css +0 -87
- package/bin/static/highlight/styles/magula.css +0 -70
- package/bin/static/highlight/styles/mono-blue.css +0 -59
- package/bin/static/highlight/styles/monokai-sublime.css +0 -83
- package/bin/static/highlight/styles/monokai.css +0 -70
- package/bin/static/highlight/styles/nord.css +0 -309
- package/bin/static/highlight/styles/obsidian.css +0 -88
- package/bin/static/highlight/styles/ocean.css +0 -74
- package/bin/static/highlight/styles/paraiso-dark.css +0 -72
- package/bin/static/highlight/styles/paraiso-light.css +0 -72
- package/bin/static/highlight/styles/pojoaque.css +0 -83
- package/bin/static/highlight/styles/pojoaque.jpg +0 -0
- package/bin/static/highlight/styles/purebasic.css +0 -96
- package/bin/static/highlight/styles/qtcreator_dark.css +0 -83
- package/bin/static/highlight/styles/qtcreator_light.css +0 -83
- package/bin/static/highlight/styles/railscasts.css +0 -106
- package/bin/static/highlight/styles/rainbow.css +0 -85
- package/bin/static/highlight/styles/routeros.css +0 -108
- package/bin/static/highlight/styles/school-book.css +0 -69
- package/bin/static/highlight/styles/school-book.png +0 -0
- package/bin/static/highlight/styles/shades-of-purple.css +0 -97
- package/bin/static/highlight/styles/solarized-dark.css +0 -84
- package/bin/static/highlight/styles/solarized-light.css +0 -84
- package/bin/static/highlight/styles/sunburst.css +0 -102
- package/bin/static/highlight/styles/tomorrow-night-blue.css +0 -75
- package/bin/static/highlight/styles/tomorrow-night-bright.css +0 -74
- package/bin/static/highlight/styles/tomorrow-night-eighties.css +0 -74
- package/bin/static/highlight/styles/tomorrow-night.css +0 -75
- package/bin/static/highlight/styles/tomorrow.css +0 -72
- package/bin/static/highlight/styles/vs.css +0 -68
- package/bin/static/highlight/styles/vs2015.css +0 -115
- package/bin/static/highlight/styles/xcode.css +0 -104
- package/bin/static/highlight/styles/xt256.css +0 -92
- package/bin/static/highlight/styles/zenburn.css +0 -80
- package/bin/static/highlight/vue-highlight.js +0 -29
- package/bin/static/ifame.html +0 -24
- package/bin/static/img/add.png +0 -0
- package/bin/static/img/avatar.png +0 -0
- package/bin/static/img/banner_2.png +0 -0
- package/bin/static/img/default.png +0 -0
- package/bin/static/img/loading.svg +0 -1
- package/bin/static/img/logo.png +0 -0
- package/bin/static/img/logo1.png +0 -0
- package/bin/static/img/logo_gray.png +0 -0
- package/bin/static/img/logo_round.png +0 -0
- package/bin/static/img/mm.ico +0 -0
- package/bin/static/img/mm.jpg +0 -0
- package/bin/static/img/select.png +0 -0
- package/bin/static/img/web.png +0 -0
- package/bin/static/index.html +0 -12
- package/bin/static/js/clipboard.min.js +0 -257
- package/bin/static/js/css.min.js +0 -1
- package/bin/static/js/echarts.js +0 -22
- package/bin/static/js/html5.min.js +0 -1
- package/bin/static/js/jquery.lazyload.min.js +0 -2
- package/bin/static/js/jquery.min.js +0 -4189
- package/bin/static/js/jquery.scrollstop.min.js +0 -2
- package/bin/static/js/mm-requirejs-vue.js +0 -283
- package/bin/static/js/mm_check.js +0 -490
- package/bin/static/js/mm_flexble.js +0 -112
- package/bin/static/js/mm_picker.js +0 -1417
- package/bin/static/js/mm_pinyinlite.js +0 -873
- package/bin/static/js/mm_sdk.js +0 -2841
- package/bin/static/js/mm_ui_expand.js +0 -468
- package/bin/static/js/mm_vue.js +0 -376
- package/bin/static/js/mm_vue_ui.js +0 -2375
- package/bin/static/js/mm_websocket.js +0 -145
- package/bin/static/js/require.js +0 -5
- package/bin/static/js/sortable.min.js +0 -3
- package/bin/static/js/swiper.min.js +0 -13
- package/bin/static/js/text.min.js +0 -1
- package/bin/static/js/vue-router.min.js +0 -6
- package/bin/static/js/vue.js +0 -12338
- package/bin/static/js/vuedraggable.min.js +0 -2
- package/bin/static/js/vuex.min.js +0 -6
- package/bin/static/src/components/bar/mm_action.vue +0 -19
- package/bin/static/src/components/bar/mm_buy.vue +0 -19
- package/bin/static/src/components/bar/mm_chat.vue +0 -18
- package/bin/static/src/components/bar/mm_count.vue +0 -18
- package/bin/static/src/components/bar/mm_filter.vue +0 -18
- package/bin/static/src/components/bar/mm_search.vue +0 -18
- package/bin/static/src/components/bar/mm_sort.vue +0 -18
- package/bin/static/src/components/bar/mm_tag.vue +0 -18
- package/bin/static/src/components/bar/mm_title.vue +0 -19
- package/bin/static/src/components/content/mm_pre.vue +0 -70
- package/bin/static/src/components/expand/mm_drag.vue +0 -39
- package/bin/static/src/components/item/mm_article.vue +0 -115
- package/bin/static/src/components/item/mm_base.vue +0 -26
- package/bin/static/src/components/item/mm_contact.vue +0 -25
- package/bin/static/src/components/item/mm_goods.vue +0 -23
- package/bin/static/src/components/item/mm_img.vue +0 -21
- package/bin/static/src/components/item/mm_media.vue +0 -18
- package/bin/static/src/components/item/mm_message.vue +0 -18
- package/bin/static/src/components/item/mm_music.vue +0 -95
- package/bin/static/src/components/item/mm_news.vue +0 -22
- package/bin/static/src/components/item/mm_number.vue +0 -26
- package/bin/static/src/components/item/mm_question.vue +0 -35
- package/bin/static/src/components/item/mm_user.vue +0 -22
- package/bin/static/src/components/item/mm_video.vue +0 -95
- package/bin/static/src/components/slide/mm_slide_card.vue +0 -64
- package/bin/static/src/components/slide/mm_slide_img.vue +0 -47
- package/bin/static/src/components/slide/mm_slide_page.vue +0 -8
- package/bin/static/src/components/slide/mm_slide_text.vue +0 -54
- package/bin/static/src/main.js +0 -84
- package/bin/static/src/mixins/form.js +0 -223
- package/bin/static/src/mixins/item.js +0 -242
- package/bin/static/src/mixins/list.js +0 -244
- package/bin/static/src/mixins/page.js +0 -1011
- package/bin/static/src/mm_component.js +0 -74
- package/bin/static/src/router.js +0 -72
- package/bin/static/src/store/user.js +0 -75
- package/bin/static/src/store/web.js +0 -50
- package/bin/static/user/1/number_info.xlsx +0 -0
- package/bin/static/w3c.html +0 -94
- package/init.js +0 -55
- package/update.md +0 -1
- /package/{bin → core}/com/api/README.md +0 -0
- /package/{bin → core}/com/api/rpc.js +0 -0
- /package/{bin → core}/com/db/README.md +0 -0
- /package/{bin → core}/com/event/README.md +0 -0
- /package/{bin/com/socket → core/com/mqtt}/README.md +0 -0
- /package/{bin → core}/com/nav/README.md +0 -0
- /package/{bin → core}/com/nav/config.tpl.json +0 -0
- /package/{bin → core}/com/param/README.md +0 -0
- /package/{bin → core}/com/param/index.js +0 -0
- /package/{bin → core}/com/param/script.js +0 -0
- /package/{bin → core}/com/param/test.js +0 -0
- /package/{bin → core}/com/plugin/README.md +0 -0
- /package/{bin → core}/com/plugin/script.js +0 -0
- /package/{bin → core}/com/sql/README.md +0 -0
- /package/{bin → core}/com/sql/index.js +0 -0
- /package/{bin → core}/com/sql/script.js +0 -0
- /package/{bin → core}/com/static/README.md +0 -0
- /package/{bin → core}/com/static/script.js +0 -0
- /package/{bin → core}/com/task/README.md +0 -0
- /package/{bin/rps.bat → rps.bat} +0 -0
- /package/{bin/tps.bat → tps.bat} +0 -0
package/index.js
CHANGED
|
@@ -1,799 +1,220 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
*
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
class MM {
|
|
1
|
+
require('mm_logs');
|
|
2
|
+
require('mm_ret');
|
|
3
|
+
$.Tpl = require('mm_tpl');
|
|
4
|
+
$.mongodb_admin = require("mm_mongodb").mongoDB_admin;
|
|
5
|
+
$.redis_admin = require("mm_redis").redis_admin;
|
|
6
|
+
$.mysql_admin = require('mm_mysql').mysql_admin;
|
|
7
|
+
const conf = require("mm_config");
|
|
8
|
+
var Com = require("./lib/com.js");
|
|
9
|
+
var App = require("./lib/app.js");
|
|
10
|
+
var Game = require("./lib/game.js");
|
|
11
|
+
const WEB = require("./core/base/web/index.js");
|
|
12
|
+
const MQTT = require("./core/base/mqtt/index.js");
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 服务端系统
|
|
16
|
+
*/
|
|
17
|
+
class Soa {
|
|
19
18
|
/**
|
|
20
19
|
* 构造函数
|
|
21
|
-
* @constructor
|
|
22
20
|
* @param {Object} config 配置参数
|
|
23
|
-
* @param {Object} server koa应用服务
|
|
24
21
|
*/
|
|
25
|
-
constructor(config
|
|
26
|
-
/**
|
|
27
|
-
* 配置参数
|
|
28
|
-
* @type {Object}
|
|
29
|
-
*/
|
|
22
|
+
constructor(config) {
|
|
30
23
|
this.config = {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
* 监听地址
|
|
38
|
-
* @type {String}
|
|
39
|
-
*/
|
|
40
|
-
host: "0.0.0.0",
|
|
41
|
-
/**
|
|
42
|
-
* 监听端口
|
|
43
|
-
* @type {Number}
|
|
44
|
-
*/
|
|
45
|
-
port: 5000,
|
|
46
|
-
/**
|
|
47
|
-
* 是否输出操作日志
|
|
48
|
-
* @type {Boolean}
|
|
49
|
-
*/
|
|
50
|
-
log: false,
|
|
51
|
-
/**
|
|
52
|
-
* 线程数, 0为根据CPU核心数创建线程数
|
|
53
|
-
* @type {Number}
|
|
54
|
-
*/
|
|
55
|
-
threads: 1
|
|
24
|
+
"runPath": __dirname,
|
|
25
|
+
"sys": {
|
|
26
|
+
"name": "mm",
|
|
27
|
+
"title": "超级美眉",
|
|
28
|
+
"cache": "memory",
|
|
29
|
+
"lang": "zh_CN"
|
|
56
30
|
},
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* 应用根目录
|
|
69
|
-
* @type {Number}
|
|
70
|
-
*/
|
|
71
|
-
app: "./app".fullname(),
|
|
72
|
-
/**
|
|
73
|
-
* 静态文件跟目录
|
|
74
|
-
* @type {String}
|
|
75
|
-
*/
|
|
76
|
-
static: './bin/static'.fullname($.binPath)
|
|
31
|
+
"web": {
|
|
32
|
+
"state": true,
|
|
33
|
+
"host": "0.0.0.0",
|
|
34
|
+
"port": 8000,
|
|
35
|
+
"socket": true,
|
|
36
|
+
"compress": true,
|
|
37
|
+
"event": true,
|
|
38
|
+
"log": true,
|
|
39
|
+
"static": true,
|
|
40
|
+
"static_path": "./static",
|
|
41
|
+
"proxy": {}
|
|
77
42
|
},
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
* 服务端名称
|
|
85
|
-
* @type {String}
|
|
86
|
-
*/
|
|
87
|
-
name: "mm",
|
|
88
|
-
/**
|
|
89
|
-
* 服务端中文名
|
|
90
|
-
* @type {String}
|
|
91
|
-
*/
|
|
92
|
-
title: "超级美眉",
|
|
93
|
-
/**
|
|
94
|
-
* 缓存方式, 选填 redis, cache, memory
|
|
95
|
-
* @type {String}
|
|
96
|
-
*/
|
|
97
|
-
cache: "redis",
|
|
98
|
-
/**
|
|
99
|
-
* 数据存储方式
|
|
100
|
-
* @type {String}
|
|
101
|
-
*/
|
|
102
|
-
db: "mysql",
|
|
103
|
-
/**
|
|
104
|
-
* 是否启用定时任务服务
|
|
105
|
-
* @type {Boolean}
|
|
106
|
-
*/
|
|
107
|
-
task: false,
|
|
108
|
-
/**
|
|
109
|
-
* 是否启用压缩
|
|
110
|
-
* @type {Boolean}
|
|
111
|
-
*/
|
|
112
|
-
compress: false,
|
|
113
|
-
/**
|
|
114
|
-
* 是否启用静态文件处理器
|
|
115
|
-
* @type {Boolean}
|
|
116
|
-
*/
|
|
117
|
-
static: true,
|
|
118
|
-
/**
|
|
119
|
-
* 是否引用com函数
|
|
120
|
-
*/
|
|
121
|
-
com: true,
|
|
122
|
-
/**
|
|
123
|
-
* 是否启用websocket通讯
|
|
124
|
-
*/
|
|
125
|
-
websocket: true,
|
|
126
|
-
/**
|
|
127
|
-
* 使用外事件
|
|
128
|
-
*/
|
|
129
|
-
event: true
|
|
43
|
+
"mqtt": {
|
|
44
|
+
"state": true,
|
|
45
|
+
"socket_port": 1883,
|
|
46
|
+
"http_port": 8083,
|
|
47
|
+
"cache": "redis",
|
|
48
|
+
"db": 12
|
|
130
49
|
},
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
/**
|
|
141
|
-
* 端口号
|
|
142
|
-
* @type {Number}
|
|
143
|
-
*/
|
|
144
|
-
port: 6379,
|
|
145
|
-
/**
|
|
146
|
-
* 密码
|
|
147
|
-
* @type {String}
|
|
148
|
-
*/
|
|
149
|
-
password: "asd123",
|
|
150
|
-
/**
|
|
151
|
-
* 选用的数据库0-9
|
|
152
|
-
* @type {Number}
|
|
153
|
-
*/
|
|
154
|
-
database: 0,
|
|
155
|
-
/**
|
|
156
|
-
* 键前缀
|
|
157
|
-
* @type {String}
|
|
158
|
-
*/
|
|
159
|
-
prefix: "mm_"
|
|
50
|
+
"mqtt_client": {
|
|
51
|
+
"state": true,
|
|
52
|
+
"host": "127.0.0.1",
|
|
53
|
+
"port": "8083",
|
|
54
|
+
"protocol": "ws",
|
|
55
|
+
"clientId": "system",
|
|
56
|
+
"username": "admin",
|
|
57
|
+
"password": "asd123",
|
|
58
|
+
"clean": false
|
|
160
59
|
},
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
* @type {String}
|
|
168
|
-
*/
|
|
169
|
-
host: "127.0.0.1",
|
|
170
|
-
/**
|
|
171
|
-
* 端口号
|
|
172
|
-
* @type {Number}
|
|
173
|
-
*/
|
|
174
|
-
port: 3306,
|
|
175
|
-
/**
|
|
176
|
-
* 用户名
|
|
177
|
-
* @type {String}
|
|
178
|
-
*/
|
|
179
|
-
user: "root",
|
|
180
|
-
/**
|
|
181
|
-
* 密码
|
|
182
|
-
* @type {String}
|
|
183
|
-
*/
|
|
184
|
-
password: "asd123",
|
|
185
|
-
/**
|
|
186
|
-
* 数据库名称
|
|
187
|
-
* @type {String}
|
|
188
|
-
*/
|
|
189
|
-
database: "mm"
|
|
60
|
+
"redis": {
|
|
61
|
+
"host": "127.0.0.1",
|
|
62
|
+
"port": 6379,
|
|
63
|
+
"password": "asd159357",
|
|
64
|
+
"database": 0,
|
|
65
|
+
"prefix": "mm_"
|
|
190
66
|
},
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
*/
|
|
198
|
-
host: "localhost",
|
|
199
|
-
/**
|
|
200
|
-
* 端口号
|
|
201
|
-
*/
|
|
202
|
-
port: 27017,
|
|
203
|
-
/**
|
|
204
|
-
* 数据库名
|
|
205
|
-
*/
|
|
206
|
-
database: "mm",
|
|
207
|
-
/**
|
|
208
|
-
* 用户名
|
|
209
|
-
*/
|
|
210
|
-
user: "admin",
|
|
211
|
-
/**
|
|
212
|
-
* 密码
|
|
213
|
-
*/
|
|
214
|
-
password: "asd123"
|
|
215
|
-
},
|
|
216
|
-
/**
|
|
217
|
-
* 重定向
|
|
218
|
-
*/
|
|
219
|
-
redirect: {
|
|
220
|
-
// 将m.开头的域名指向到/phone/路由路径
|
|
221
|
-
"m.*": "/phone/",
|
|
222
|
-
"pad.*": "/pad/",
|
|
223
|
-
"tv.*": "/tv/"
|
|
224
|
-
},
|
|
225
|
-
/**
|
|
226
|
-
* 代理
|
|
227
|
-
*/
|
|
228
|
-
proxy: {
|
|
229
|
-
// 转发到web socket服务器
|
|
230
|
-
webscoket: {
|
|
231
|
-
path: ["/ws/*"],
|
|
232
|
-
com: ["*"]
|
|
233
|
-
},
|
|
234
|
-
// 转发到开发者服务器
|
|
235
|
-
dev: {
|
|
236
|
-
path: ["/dev/*", "/api/dev/*"],
|
|
237
|
-
com: ["task", "app"]
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
};
|
|
241
|
-
|
|
242
|
-
if (config) {
|
|
243
|
-
$.push(this.config, config, true);
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* 数据库管理器
|
|
248
|
-
*/
|
|
249
|
-
this.db = {};
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* 事件集合
|
|
253
|
-
*/
|
|
254
|
-
this.events = {
|
|
255
|
-
/**
|
|
256
|
-
* 请求前
|
|
257
|
-
*/
|
|
258
|
-
before: [],
|
|
259
|
-
/**
|
|
260
|
-
* 验证
|
|
261
|
-
*/
|
|
262
|
-
check: [],
|
|
263
|
-
/**
|
|
264
|
-
* 主要
|
|
265
|
-
*/
|
|
266
|
-
main: [],
|
|
267
|
-
/**
|
|
268
|
-
* 渲染
|
|
269
|
-
*/
|
|
270
|
-
render: [],
|
|
271
|
-
/**
|
|
272
|
-
* 请求后
|
|
273
|
-
*/
|
|
274
|
-
after: []
|
|
275
|
-
};
|
|
276
|
-
|
|
277
|
-
/**
|
|
278
|
-
* 路由集合
|
|
279
|
-
*/
|
|
280
|
-
this.routes = {
|
|
281
|
-
post: [],
|
|
282
|
-
get: []
|
|
283
|
-
};
|
|
284
|
-
|
|
285
|
-
$.push(server, this, true);
|
|
286
|
-
$.config = init(this.config);
|
|
287
|
-
|
|
288
|
-
if (this.config.sys.event && $.event_admin) {
|
|
289
|
-
// 创建一个API事件
|
|
290
|
-
var apis = $.event_admin('api', 'API事件');
|
|
291
|
-
apis.update();
|
|
292
|
-
for (var k in this.events) {
|
|
293
|
-
this.events[k] = apis["list_" + k];
|
|
67
|
+
"mongodb": {
|
|
68
|
+
"host": "127.0.0.1",
|
|
69
|
+
"port": 27017,
|
|
70
|
+
"database": "mm",
|
|
71
|
+
"user": "admin",
|
|
72
|
+
"password": "asd123"
|
|
294
73
|
}
|
|
295
74
|
};
|
|
296
|
-
|
|
297
|
-
// WAF(web防火墙)
|
|
298
|
-
waf(server);
|
|
299
|
-
|
|
300
|
-
// 引入web socket通讯
|
|
301
|
-
server = websocket(server);
|
|
302
|
-
|
|
303
|
-
// 设置session 保存时长2小时
|
|
304
|
-
server.use(session({
|
|
305
|
-
maxAge: 7200
|
|
306
|
-
}));
|
|
307
|
-
|
|
308
|
-
if (this.config.sys.websocket && $.Socket) {
|
|
309
|
-
//使用 websocket 服务
|
|
310
|
-
const Socket = $.Socket;
|
|
311
|
-
$.socket = new Socket();
|
|
312
|
-
$.socket.update();
|
|
313
|
-
server.ws.use($.socket.run);
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* 路由前后事件
|
|
318
|
-
*/
|
|
319
|
-
server.use(async (ctx, next) => {
|
|
320
|
-
ctx.db = {};
|
|
321
|
-
var db = ctx.db;
|
|
322
|
-
db.ret = null;
|
|
323
|
-
var ret = await this.run_event(ctx, this.events.before, db);
|
|
324
|
-
if (!ret) {
|
|
325
|
-
await next();
|
|
326
|
-
ret = await this.run_event(ctx, this.events.after, db) || db.ret;
|
|
327
|
-
}
|
|
328
|
-
if (ret) {
|
|
329
|
-
ctx.body = ret;
|
|
330
|
-
ctx.status = ctx.status == 404 ? 200 : ctx.status;
|
|
331
|
-
}
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
// 使用压缩
|
|
335
|
-
if (this.config.sys.compress) {
|
|
336
|
-
server.use(
|
|
337
|
-
compress({
|
|
338
|
-
filter: function(content_type) {
|
|
339
|
-
// 只有在请求的content-type中有gzip类型,我们才会考虑压缩,因为zlib是压缩成gzip类型的
|
|
340
|
-
return /text/i.test(content_type);
|
|
341
|
-
},
|
|
342
|
-
// 阀值,当数据超过1kb的时候,可以压缩
|
|
343
|
-
threshold: 1024,
|
|
344
|
-
// zlib是node的压缩模块
|
|
345
|
-
flush: require('zlib').Z_SYNC_FLUSH
|
|
346
|
-
})
|
|
347
|
-
);
|
|
348
|
-
}
|
|
349
|
-
|
|
350
|
-
// 处理静态文件
|
|
351
|
-
if (this.config.sys.static) {
|
|
352
|
-
server.use(statics(
|
|
353
|
-
this.config.path.static, {
|
|
354
|
-
maxAge: 60 * 60 * 24 * 7,
|
|
355
|
-
gzip: true,
|
|
356
|
-
brotli: true
|
|
357
|
-
}));
|
|
358
|
-
}
|
|
359
|
-
|
|
360
|
-
// 使用多路径静态文件处理器
|
|
361
|
-
if (this.config.sys.static && $.Static) {
|
|
362
|
-
const Static = $.Static;
|
|
363
|
-
$.static = new Static();
|
|
364
|
-
$.static.update();
|
|
365
|
-
server.use($.static.run);
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
// 解析 text/xml
|
|
369
|
-
server.use(xmlParser());
|
|
370
|
-
|
|
371
|
-
// 解析 application/json、application/x-www-form-urlencoded、text/plain
|
|
372
|
-
// 接收主体
|
|
373
|
-
server.use(koaBody({
|
|
374
|
-
multipart: true,
|
|
375
|
-
formidable: {
|
|
376
|
-
// 设置上传文件大小最大限制,默认20M
|
|
377
|
-
maxFileSize: 2000 * 1024 * 1024
|
|
378
|
-
}
|
|
379
|
-
}));
|
|
380
|
-
|
|
381
|
-
// 追加主程序
|
|
382
|
-
this.main("/*", async (ctx, db) => {
|
|
383
|
-
var md = ctx.method.toLocaleLowerCase();
|
|
384
|
-
var list = this.routes[md];
|
|
385
|
-
return await this.run_route(ctx, db, list);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
// 使用路由(主要)
|
|
389
|
-
server.use(async (ctx, next) => {
|
|
390
|
-
var db = ctx.db;
|
|
391
|
-
var path = ctx.path;
|
|
392
|
-
if (path !== "/favicon.ico") {
|
|
393
|
-
db.ret = await this.run_event(ctx, this.events.check, db);
|
|
394
|
-
if (!db.ret) {
|
|
395
|
-
db.ret = await this.run_event(ctx, this.events.main, db);
|
|
396
|
-
}
|
|
397
|
-
db.ret = await this.run_event(ctx, this.events.render, db) || db.ret;
|
|
398
|
-
}
|
|
399
|
-
if (db.ret) {
|
|
400
|
-
ctx.body = db.ret;
|
|
401
|
-
} else {
|
|
402
|
-
next();
|
|
403
|
-
}
|
|
404
|
-
});
|
|
405
|
-
|
|
406
|
-
if (this.config.sys.task && $.event_admin) {
|
|
407
|
-
// 创建一个任务管理器
|
|
408
|
-
$.task = $.task_admin('sys');
|
|
409
|
-
$.task.update();
|
|
410
|
-
// 启动计时器
|
|
411
|
-
$.timer.start();
|
|
412
|
-
console.log('已启动定时任务!');
|
|
413
|
-
};
|
|
414
|
-
return server;
|
|
75
|
+
this.init(config);
|
|
415
76
|
}
|
|
416
77
|
}
|
|
417
78
|
|
|
418
79
|
/**
|
|
419
|
-
*
|
|
420
|
-
* @param {Object}
|
|
421
|
-
* @param {Function} next 跳过当前
|
|
422
|
-
* @param {Array} list 路由列表
|
|
423
|
-
* @param {Object} db 数据管理器
|
|
80
|
+
* 初始化数据
|
|
81
|
+
* @param {Object} config
|
|
424
82
|
*/
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
for (var i = 0; i < list.length; i++) {
|
|
430
|
-
var o = list[i];
|
|
431
|
-
var cg = o.config;
|
|
432
|
-
if (cg.method == "ALL" || cg.method == method) {
|
|
433
|
-
if (o.onOff && path.has(cg.target)) {
|
|
434
|
-
var ret = await o.run(ctx, db);
|
|
435
|
-
if (ret) {
|
|
436
|
-
db.ret = ret;
|
|
437
|
-
if (cg.end) {
|
|
438
|
-
break;
|
|
439
|
-
}
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
} catch (e) {
|
|
445
|
-
console.log(e);
|
|
83
|
+
Soa.prototype.initData = function(config) {
|
|
84
|
+
var p = config.runPath;
|
|
85
|
+
if (p.substring(p.length - 1) !== $.slash) {
|
|
86
|
+
config.runPath += $.slash;
|
|
446
87
|
}
|
|
447
|
-
return db.ret;
|
|
448
|
-
};
|
|
449
88
|
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
var o = list[i];
|
|
462
|
-
var cg = o.config;
|
|
463
|
-
if (o.onOff && path.has(cg.path)) {
|
|
464
|
-
var ret = await o.run(ctx, db);
|
|
465
|
-
if (ret) {
|
|
466
|
-
db.ret = ret;
|
|
467
|
-
}
|
|
468
|
-
if (cg.end) {
|
|
469
|
-
break;
|
|
470
|
-
}
|
|
471
|
-
}
|
|
89
|
+
$.runPath = config.runPath;
|
|
90
|
+
|
|
91
|
+
// 修改默认模板路径,改为static下,方便读取css和js
|
|
92
|
+
$.Tpl.prototype.init = function(config) {
|
|
93
|
+
if (config) {
|
|
94
|
+
if (!config.defualt_dir) {
|
|
95
|
+
config.defualt_dir = "./static/template/".fullname();
|
|
96
|
+
}
|
|
97
|
+
} else {
|
|
98
|
+
config = {
|
|
99
|
+
defualt_dir: "./static/template/".fullname()
|
|
472
100
|
}
|
|
473
101
|
}
|
|
474
|
-
|
|
475
|
-
|
|
102
|
+
this.set_config(config);
|
|
103
|
+
this.dir = config.defualt_dir;
|
|
476
104
|
}
|
|
477
|
-
return db.ret;
|
|
478
|
-
};
|
|
479
|
-
|
|
480
|
-
/**
|
|
481
|
-
* 新建事件模型
|
|
482
|
-
* @param {Object} obj 附加值
|
|
483
|
-
* @return {Object} 返回模型
|
|
484
|
-
*/
|
|
485
|
-
MM.prototype.event_model = function(obj, run) {
|
|
486
|
-
return {
|
|
487
|
-
// 开关
|
|
488
|
-
onOff: true,
|
|
489
|
-
// 配置参数
|
|
490
|
-
config: Object.assign({
|
|
491
|
-
// 接受的请求方式
|
|
492
|
-
method: "ALL",
|
|
493
|
-
// 目标
|
|
494
|
-
target: "",
|
|
495
|
-
// 排序
|
|
496
|
-
sort: 100,
|
|
497
|
-
// 结束
|
|
498
|
-
end: true,
|
|
499
|
-
}, obj),
|
|
500
|
-
// 回调函数
|
|
501
|
-
run: run || function(ctx, db) {
|
|
502
|
-
return null;
|
|
503
|
-
}
|
|
504
|
-
};
|
|
505
|
-
};
|
|
506
105
|
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
* @param {Object} obj 附加值
|
|
510
|
-
* @return {Object} 返回模型
|
|
511
|
-
*/
|
|
512
|
-
MM.prototype.route_model = function(obj, run) {
|
|
513
|
-
return {
|
|
514
|
-
// 开关
|
|
515
|
-
onOff: true,
|
|
516
|
-
// 配置参数
|
|
517
|
-
config: Object.assign({
|
|
518
|
-
// 接受的请求方式
|
|
519
|
-
method: "GET",
|
|
520
|
-
// 请求路径
|
|
521
|
-
path: "",
|
|
522
|
-
// 排序
|
|
523
|
-
sort: 100,
|
|
524
|
-
// 结束
|
|
525
|
-
end: true,
|
|
526
|
-
// 缓存时长, 单位:分钟
|
|
527
|
-
cache: 0,
|
|
528
|
-
// 缓存方式 client客户端缓存, server服务端缓存
|
|
529
|
-
cache_method: "client server"
|
|
530
|
-
}, obj),
|
|
531
|
-
// 回调函数
|
|
532
|
-
run: run || function(ctx, db) {
|
|
533
|
-
return null;
|
|
534
|
-
}
|
|
535
|
-
};
|
|
536
|
-
};
|
|
537
|
-
|
|
538
|
-
/**
|
|
539
|
-
* 添加post路由
|
|
540
|
-
* @param {String} path 路由路径
|
|
541
|
-
* @param {Function} func 回调函数
|
|
542
|
-
* @param {Number} sort 排列顺序
|
|
543
|
-
*/
|
|
544
|
-
MM.prototype.post = function(path, run, sort = 100) {
|
|
545
|
-
this.routes["post"].push(this.route_model({
|
|
546
|
-
method: "POST",
|
|
547
|
-
path,
|
|
548
|
-
sort
|
|
549
|
-
}, run));
|
|
550
|
-
this.route_sort('post');
|
|
551
|
-
};
|
|
552
|
-
|
|
553
|
-
/**
|
|
554
|
-
* 添加get路由
|
|
555
|
-
* @param {String} path 路由路径
|
|
556
|
-
* @param {Function} func 回调函数
|
|
557
|
-
* @param {Number} sort 排列顺序
|
|
558
|
-
*/
|
|
559
|
-
MM.prototype.get = function(path, run, sort = 100) {
|
|
560
|
-
this.routes["get"].push(this.route_model({
|
|
561
|
-
method: "GET",
|
|
562
|
-
path,
|
|
563
|
-
sort
|
|
564
|
-
}, run));
|
|
565
|
-
this.route_sort('get');
|
|
566
|
-
};
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* 请求前
|
|
570
|
-
* @param {String} target 目标
|
|
571
|
-
* @param {Function} func 回调函数
|
|
572
|
-
* @param {Number} sort 排列顺序
|
|
573
|
-
*/
|
|
574
|
-
MM.prototype.before = function(target, run, sort = 100) {
|
|
575
|
-
this.events["before"].push(this.event_model({
|
|
576
|
-
end: false,
|
|
577
|
-
target,
|
|
578
|
-
sort
|
|
579
|
-
}, run));
|
|
580
|
-
this.event_sort('before');
|
|
581
|
-
};
|
|
582
|
-
|
|
583
|
-
/**
|
|
584
|
-
* 请求后
|
|
585
|
-
* @param {String} target 目标
|
|
586
|
-
* @param {Function} func 回调函数
|
|
587
|
-
* @param {Number} sort 排列顺序
|
|
588
|
-
*/
|
|
589
|
-
MM.prototype.check = function(target, run, sort = 100) {
|
|
590
|
-
this.events["check"].push(this.event_model({
|
|
591
|
-
target,
|
|
592
|
-
sort
|
|
593
|
-
}, run));
|
|
594
|
-
this.event_sort('check');
|
|
595
|
-
};
|
|
106
|
+
// 初始化公共函数
|
|
107
|
+
$.func = {};
|
|
596
108
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
*/
|
|
603
|
-
MM.prototype.main = function(target, run, sort = 100) {
|
|
604
|
-
this.events["main"].push(this.event_model({
|
|
605
|
-
end: false,
|
|
606
|
-
target,
|
|
607
|
-
sort
|
|
608
|
-
}, run));
|
|
609
|
-
this.event_sort('main');
|
|
610
|
-
};
|
|
109
|
+
// 初始化变量
|
|
110
|
+
$.var = {};
|
|
111
|
+
$.conf = conf(null, '/conf.json'.fullname());
|
|
112
|
+
$.config = config;
|
|
113
|
+
}
|
|
611
114
|
|
|
612
115
|
/**
|
|
613
|
-
*
|
|
614
|
-
* @param {
|
|
615
|
-
* @param {Function} func 回调函数
|
|
616
|
-
* @param {Number} sort 排列顺序
|
|
116
|
+
* 加载核心模块
|
|
117
|
+
* @param {Object} config
|
|
617
118
|
*/
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
this.
|
|
624
|
-
|
|
119
|
+
Soa.prototype.loadModule = function(config) {
|
|
120
|
+
$.com = new Com();
|
|
121
|
+
$.app = new App();
|
|
122
|
+
$.game = new Game();
|
|
123
|
+
this.com = $.com;
|
|
124
|
+
this.app = $.app;
|
|
125
|
+
this.game = $.game;
|
|
126
|
+
}
|
|
625
127
|
|
|
626
128
|
/**
|
|
627
|
-
*
|
|
628
|
-
* @param {
|
|
629
|
-
* @param {Function} func 回调函数
|
|
630
|
-
* @param {Number} sort 排列顺序
|
|
129
|
+
* 初始化
|
|
130
|
+
* @param {Object} config 配置参数
|
|
631
131
|
*/
|
|
632
|
-
|
|
633
|
-
this.
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
}, run));
|
|
638
|
-
this.event_sort('after');
|
|
639
|
-
};
|
|
640
|
-
|
|
132
|
+
Soa.prototype.init = function(config) {
|
|
133
|
+
this.config = Object.assign(this.config, config);
|
|
134
|
+
this.initData(this.config);
|
|
135
|
+
this.loadModule(this.config);
|
|
136
|
+
}
|
|
641
137
|
|
|
642
138
|
/**
|
|
643
|
-
*
|
|
644
|
-
* @param {Object} obj_a 对象A
|
|
645
|
-
* @param {Object} obj_b 对象B
|
|
139
|
+
* 运行基础数据
|
|
646
140
|
*/
|
|
647
|
-
|
|
648
|
-
var
|
|
649
|
-
|
|
650
|
-
var
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
141
|
+
Soa.prototype.runBase = function() {
|
|
142
|
+
var middleware = $.middleware;
|
|
143
|
+
middleware.init();
|
|
144
|
+
var cg = this.config;
|
|
145
|
+
var mqtt, web;
|
|
146
|
+
if (cg.web && cg.web.state) {
|
|
147
|
+
web = new WEB(cg.web);
|
|
148
|
+
web.list = middleware.list.filter((o) => {
|
|
149
|
+
return !o.mode || o.mode == "web"
|
|
150
|
+
});
|
|
151
|
+
web.init();
|
|
152
|
+
this.web = web;
|
|
655
153
|
}
|
|
656
|
-
};
|
|
657
154
|
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
this.routes["post"].sort(this.route_sort_way);
|
|
669
|
-
this.routes["get"].sort(this.route_sort_way);
|
|
155
|
+
if (cg.mqtt && cg.mqtt.state) {
|
|
156
|
+
mqtt = new MQTT(Object.assign(cg.mqtt, {
|
|
157
|
+
redis: cg.redis,
|
|
158
|
+
mongodb: cg.mongodb
|
|
159
|
+
}));
|
|
160
|
+
mqtt.list = middleware.list.filter((o) => {
|
|
161
|
+
return o.mode == "mqtt"
|
|
162
|
+
});
|
|
163
|
+
mqtt.init();
|
|
164
|
+
this.mqtt = mqtt;
|
|
670
165
|
}
|
|
671
|
-
}
|
|
166
|
+
}
|
|
672
167
|
|
|
673
|
-
/**
|
|
674
|
-
* 事件排序方式
|
|
675
|
-
* @param {Object} obj_a 对象A
|
|
676
|
-
* @param {Object} obj_b 对象B
|
|
677
|
-
*/
|
|
678
|
-
MM.prototype.event_sort_way = function(obj_a, obj_b) {
|
|
679
|
-
var a = obj_a.config;
|
|
680
|
-
var b = obj_b.config;
|
|
681
|
-
var n = a.sort - b.sort;
|
|
682
|
-
if (n == 0) {
|
|
683
|
-
return b.target.length - a.target.length;
|
|
684
|
-
} else {
|
|
685
|
-
return n;
|
|
686
|
-
}
|
|
687
|
-
};
|
|
688
168
|
|
|
689
169
|
/**
|
|
690
|
-
*
|
|
691
|
-
* @param {String}
|
|
170
|
+
* 运行主程序
|
|
171
|
+
* @param {String} state 状态
|
|
692
172
|
*/
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
173
|
+
Soa.prototype.main = async function(state) {
|
|
174
|
+
var cg = this.config;
|
|
175
|
+
var web_server = this.web_server;
|
|
176
|
+
var mqtt_server = this.mqtt_server;
|
|
177
|
+
var tip = "启动";
|
|
178
|
+
if (cg.web && cg.web.state) {
|
|
179
|
+
tip += " web";
|
|
180
|
+
if (cg.web.socket) {
|
|
181
|
+
tip += " socket";
|
|
697
182
|
}
|
|
698
|
-
|
|
699
|
-
this.events["before"].sort(this.event_sort_way);
|
|
700
|
-
this.events["check"].sort(this.event_sort_way);
|
|
701
|
-
this.events["main"].sort(this.event_sort_way);
|
|
702
|
-
this.events["render"].sort(this.event_sort_way);
|
|
703
|
-
this.events["after"].sort(this.event_sort_way);
|
|
183
|
+
this.web.run();
|
|
704
184
|
}
|
|
705
|
-
};
|
|
706
185
|
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
* @param {Array} list 排序类型
|
|
711
|
-
* @param {String} paths 路径集合
|
|
712
|
-
* @param {String} key 主键
|
|
713
|
-
*/
|
|
714
|
-
MM.prototype.shift = function(lt, list, paths, key = "target") {
|
|
715
|
-
for (var i = list.length - 1; i >= 0; i--) {
|
|
716
|
-
var o = list[i];
|
|
717
|
-
var p = o.config[key];
|
|
718
|
-
for (var n = 0; n < paths.length; n++) {
|
|
719
|
-
if (p.has(paths[n])) {
|
|
720
|
-
lt.push(o);
|
|
721
|
-
list.splice(i, 1);
|
|
722
|
-
};
|
|
723
|
-
}
|
|
186
|
+
if (cg.mqtt && cg.mqtt.state) {
|
|
187
|
+
this.mqtt.run();
|
|
188
|
+
tip += " mqtt";
|
|
724
189
|
}
|
|
190
|
+
$.log.info(tip);
|
|
725
191
|
};
|
|
726
192
|
|
|
727
|
-
|
|
728
193
|
/**
|
|
729
|
-
*
|
|
194
|
+
* 运行主程序前
|
|
195
|
+
* @param {String} state 状态
|
|
730
196
|
*/
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
for (var k in config.proxy) {
|
|
735
|
-
var cg = config.proxy[k];
|
|
736
|
-
var p = cg.path;
|
|
737
|
-
var server = new MM(Object.assign({}, config));
|
|
738
|
-
this.shift(server.routes["get"], this.routes["get"], p, "path");
|
|
739
|
-
this.shift(server.routes["post"], this.routes["post"], p, "path");
|
|
740
|
-
this.shift(server.events["before"], this.events["before"], p);
|
|
741
|
-
this.shift(server.events["check"], this.events["check"], p);
|
|
742
|
-
this.shift(server.events["main"], this.events["main"], p);
|
|
743
|
-
this.shift(server.events["render"], this.events["render"], p);
|
|
744
|
-
this.shift(server.events["after"], this.events["after"], p);
|
|
745
|
-
server.call = compose(server.middleware);
|
|
746
|
-
servers[k] = server;
|
|
747
|
-
this.use(servers[k].call);
|
|
748
|
-
}
|
|
749
|
-
this.servers = servers;
|
|
197
|
+
Soa.prototype.before = async function(state) {
|
|
198
|
+
this.runBase();
|
|
199
|
+
await this.app.initApp();
|
|
750
200
|
};
|
|
751
201
|
|
|
752
202
|
/**
|
|
753
|
-
*
|
|
754
|
-
* @param {
|
|
203
|
+
* 运行主程序后
|
|
204
|
+
* @param {String} state 状态
|
|
755
205
|
*/
|
|
756
|
-
|
|
757
|
-
// this.run_server(this.config);
|
|
758
|
-
var {
|
|
759
|
-
threads,
|
|
760
|
-
host,
|
|
761
|
-
port
|
|
762
|
-
} = this.config.web;
|
|
206
|
+
Soa.prototype.after = async function(state) {
|
|
763
207
|
|
|
764
|
-
if (!func) {
|
|
765
|
-
func = function() {
|
|
766
|
-
$.log.info('启动服务', `访问地址 http://${host}:${port}`);
|
|
767
|
-
}
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
if(threads == 1){
|
|
771
|
-
this.listen(port, host, func);
|
|
772
|
-
}
|
|
773
|
-
else {
|
|
774
|
-
if (!threads) {
|
|
775
|
-
threads = require('os').cpus().length;
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
if (cluster.isMaster) {
|
|
779
|
-
for (var i = 0; i < threads; i++) {
|
|
780
|
-
cluster.fork();
|
|
781
|
-
}
|
|
782
|
-
cluster.on('listening', function(worker, address) {});
|
|
783
|
-
} else if (cluster.isWorker) {
|
|
784
|
-
this.listen(port, host, func);
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
208
|
};
|
|
788
209
|
|
|
789
210
|
/**
|
|
790
|
-
*
|
|
791
|
-
* @param {String}
|
|
211
|
+
* 运行
|
|
212
|
+
* @param {String} state 状态
|
|
792
213
|
*/
|
|
793
|
-
|
|
794
|
-
this.
|
|
795
|
-
this.
|
|
214
|
+
Soa.prototype.run = async function(state = 'start') {
|
|
215
|
+
await this.before(state);
|
|
216
|
+
await this.main(state);
|
|
217
|
+
await this.after(state);
|
|
796
218
|
};
|
|
797
219
|
|
|
798
|
-
|
|
799
|
-
module.exports = MM;
|
|
220
|
+
module.exports = Soa;
|