mm_os 1.3.3 → 1.3.5
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
|
@@ -36,19 +36,29 @@ function waf_check(url) {
|
|
|
36
36
|
return null;
|
|
37
37
|
}
|
|
38
38
|
|
|
39
|
+
function getClientIP(req) {
|
|
40
|
+
return req.headers['x-forwarded-for'] || req.headers['X-Forwarded-For'] ||
|
|
41
|
+
req.connection.remoteAddress ||
|
|
42
|
+
req.socket.remoteAddress ||
|
|
43
|
+
req.connection.socket.remoteAddress;
|
|
44
|
+
};
|
|
45
|
+
|
|
39
46
|
/**
|
|
40
47
|
* 应用
|
|
41
48
|
* @param {Object} server 服务
|
|
49
|
+
* @param {Object} config 配置参数
|
|
42
50
|
*/
|
|
43
|
-
module.exports = function(server) {
|
|
51
|
+
module.exports = function(server, config) {
|
|
44
52
|
/* WAF(web防火墙) */
|
|
45
53
|
server.use(async (ctx, next) => {
|
|
46
54
|
var url = ctx.url;
|
|
47
55
|
var danger = waf_check(url);
|
|
48
56
|
if (danger) {
|
|
49
|
-
|
|
57
|
+
var ip = getClientIP(ctx.req);
|
|
58
|
+
$.log.warn(`检测到来自IP ${ip} 的攻击`, "规则:", danger.toString());
|
|
50
59
|
} else {
|
|
51
60
|
await next();
|
|
52
61
|
}
|
|
53
62
|
});
|
|
63
|
+
return server;
|
|
54
64
|
};
|
|
@@ -0,0 +1,67 @@
|
|
|
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
|
+
* 应用
|
|
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
|
+
ctx.send = async function(src){
|
|
18
|
+
await send(ctx, src);
|
|
19
|
+
}
|
|
20
|
+
await next();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
// 设置session 保存时长2小时
|
|
24
|
+
server.use(session({
|
|
25
|
+
maxAge: 7200
|
|
26
|
+
}));
|
|
27
|
+
|
|
28
|
+
// 使用压缩
|
|
29
|
+
if (config.compress) {
|
|
30
|
+
server.use(
|
|
31
|
+
compress({
|
|
32
|
+
filter: function(content_type) {
|
|
33
|
+
// 只有在请求的content-type中有gzip类型,我们才会考虑压缩,因为zlib是压缩成gzip类型的
|
|
34
|
+
return /text/i.test(content_type);
|
|
35
|
+
},
|
|
36
|
+
// 阀值,当数据超过1kb的时候,可以压缩
|
|
37
|
+
threshold: 1024,
|
|
38
|
+
// zlib是node的压缩模块
|
|
39
|
+
flush: require('zlib').Z_SYNC_FLUSH
|
|
40
|
+
})
|
|
41
|
+
);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// 解析 text/xml
|
|
45
|
+
server.use(xmlParser());
|
|
46
|
+
|
|
47
|
+
var func = koaBody({
|
|
48
|
+
jsonLimit: config.jsonLimit || '20mb',
|
|
49
|
+
multipart: true,
|
|
50
|
+
formidable: {
|
|
51
|
+
// 设置上传文件大小最大限制,默认20M
|
|
52
|
+
maxFileSize: 2000 * 1024 * 1024
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
// 解析 application/json、application/x-www-form-urlencoded、text/plain
|
|
57
|
+
// 接收主体
|
|
58
|
+
server.use(async(ctx, next) => {
|
|
59
|
+
if(!ctx.request.body){
|
|
60
|
+
await func(ctx, next);
|
|
61
|
+
}
|
|
62
|
+
else {
|
|
63
|
+
await next();
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
return server;
|
|
67
|
+
};
|
|
@@ -0,0 +1,411 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 拓展类
|
|
3
|
+
* @class
|
|
4
|
+
*/
|
|
5
|
+
class Event {
|
|
6
|
+
/**
|
|
7
|
+
* 构造函数
|
|
8
|
+
* @constructor
|
|
9
|
+
* @param {Object} config 配置参数
|
|
10
|
+
*/
|
|
11
|
+
constructor(server, config) {
|
|
12
|
+
/**
|
|
13
|
+
* 事件集合
|
|
14
|
+
*/
|
|
15
|
+
this.events = {
|
|
16
|
+
/**
|
|
17
|
+
* 请求前
|
|
18
|
+
*/
|
|
19
|
+
before: [],
|
|
20
|
+
/**
|
|
21
|
+
* 验证
|
|
22
|
+
*/
|
|
23
|
+
check: [],
|
|
24
|
+
/**
|
|
25
|
+
* 主要
|
|
26
|
+
*/
|
|
27
|
+
main: [],
|
|
28
|
+
/**
|
|
29
|
+
* 渲染
|
|
30
|
+
*/
|
|
31
|
+
render: [],
|
|
32
|
+
/**
|
|
33
|
+
* 请求后
|
|
34
|
+
*/
|
|
35
|
+
after: []
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 路由集合
|
|
40
|
+
*/
|
|
41
|
+
this.routes = {
|
|
42
|
+
post: [],
|
|
43
|
+
get: []
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
$.push(server, this, true);
|
|
47
|
+
|
|
48
|
+
if (config.event && $.event_admin) {
|
|
49
|
+
// 创建一个API事件
|
|
50
|
+
var apis = $.event_admin('api', 'API事件');
|
|
51
|
+
apis.update();
|
|
52
|
+
for (var k in this.events) {
|
|
53
|
+
this.events[k] = apis["list_" + k];
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 路由前后事件
|
|
59
|
+
*/
|
|
60
|
+
server.use(async (ctx, next) => {
|
|
61
|
+
ctx.db = {};
|
|
62
|
+
var db = ctx.db;
|
|
63
|
+
db.ret = null;
|
|
64
|
+
if (ctx.path !== "/favicon.ico") {
|
|
65
|
+
var ret = await this.run_event(ctx, this.events.before, db);
|
|
66
|
+
if (!ret) {
|
|
67
|
+
await next();
|
|
68
|
+
ret = await this.run_event(ctx, this.events.after, db) || db.ret;
|
|
69
|
+
if (ret) {
|
|
70
|
+
ctx.body = ret;
|
|
71
|
+
ctx.status = ctx.status == 404 ? 200 : ctx.status;
|
|
72
|
+
}
|
|
73
|
+
} else {
|
|
74
|
+
ctx.body = ret;
|
|
75
|
+
ctx.status = ctx.status == 404 ? 200 : ctx.status;
|
|
76
|
+
next();
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
next();
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
return server;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 执行
|
|
89
|
+
* @param {Object} ctx 请求上下文
|
|
90
|
+
* @param {Function} next 跳过当前
|
|
91
|
+
* @param {Array} list 路由列表
|
|
92
|
+
* @param {Object} db 数据管理器
|
|
93
|
+
*/
|
|
94
|
+
Event.prototype.run_event = async function(ctx, list, db) {
|
|
95
|
+
try {
|
|
96
|
+
var path = ctx.path.toLocaleLowerCase();
|
|
97
|
+
var method = ctx.method;
|
|
98
|
+
for (var i = 0; i < list.length; i++) {
|
|
99
|
+
var o = list[i];
|
|
100
|
+
var cg = o.config;
|
|
101
|
+
if (cg.method == "ALL" || cg.method == method) {
|
|
102
|
+
if (cg.state === 1 && path.has(cg.target)) {
|
|
103
|
+
var ret = await o.run(ctx, db);
|
|
104
|
+
if (ret) {
|
|
105
|
+
db.ret = ret;
|
|
106
|
+
if (cg.end) {
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
} catch (e) {
|
|
114
|
+
console.log(e);
|
|
115
|
+
}
|
|
116
|
+
return db.ret;
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* 执行
|
|
121
|
+
* @param {Object} ctx 请求上下文
|
|
122
|
+
* @param {Object} db 数据库管理器
|
|
123
|
+
* @param {Array} list 路由列表
|
|
124
|
+
*/
|
|
125
|
+
Event.prototype.run_route = async function(ctx, db, list) {
|
|
126
|
+
try {
|
|
127
|
+
if (list) {
|
|
128
|
+
var path = ctx.path.toLocaleLowerCase();
|
|
129
|
+
for (var i = 0; i < list.length; i++) {
|
|
130
|
+
var o = list[i];
|
|
131
|
+
var cg = o.config;
|
|
132
|
+
if (cg.state === 1 && path.has(cg.path)) {
|
|
133
|
+
var ret = await o.run(ctx, db);
|
|
134
|
+
if (ret) {
|
|
135
|
+
db.ret = ret;
|
|
136
|
+
}
|
|
137
|
+
if (cg.end) {
|
|
138
|
+
break;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
} catch (e) {
|
|
144
|
+
console.log(e);
|
|
145
|
+
}
|
|
146
|
+
return db.ret;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
/**
|
|
150
|
+
* 新建事件模型
|
|
151
|
+
* @param {Object} obj 附加值
|
|
152
|
+
* @return {Object} 返回模型
|
|
153
|
+
*/
|
|
154
|
+
Event.prototype.event_model = function(obj, run) {
|
|
155
|
+
return {
|
|
156
|
+
// 配置参数
|
|
157
|
+
config: Object.assign({
|
|
158
|
+
// 接受的请求方式
|
|
159
|
+
method: "ALL",
|
|
160
|
+
// 目标
|
|
161
|
+
target: "",
|
|
162
|
+
// 排序
|
|
163
|
+
sort: 100,
|
|
164
|
+
// 结束
|
|
165
|
+
end: true,
|
|
166
|
+
}, obj),
|
|
167
|
+
// 回调函数
|
|
168
|
+
run: run || function(ctx, db) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
};
|
|
173
|
+
|
|
174
|
+
/**
|
|
175
|
+
* 新建路由模型
|
|
176
|
+
* @param {Object} obj 附加值
|
|
177
|
+
* @return {Object} 返回模型
|
|
178
|
+
*/
|
|
179
|
+
Event.prototype.route_model = function(obj, run) {
|
|
180
|
+
return {
|
|
181
|
+
// 配置参数
|
|
182
|
+
config: Object.assign({
|
|
183
|
+
// 接受的请求方式
|
|
184
|
+
method: "GET",
|
|
185
|
+
// 请求路径
|
|
186
|
+
path: "",
|
|
187
|
+
// 排序
|
|
188
|
+
sort: 100,
|
|
189
|
+
// 结束
|
|
190
|
+
end: true,
|
|
191
|
+
// 缓存时长, 单位:分钟
|
|
192
|
+
cache: 0,
|
|
193
|
+
// 缓存方式 client客户端缓存, server服务端缓存
|
|
194
|
+
cache_method: "client server"
|
|
195
|
+
}, obj),
|
|
196
|
+
// 回调函数
|
|
197
|
+
run: run || function(ctx, db) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
};
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* 添加post路由
|
|
205
|
+
* @param {String} path 路由路径
|
|
206
|
+
* @param {Function} func 回调函数
|
|
207
|
+
* @param {Number} sort 排列顺序
|
|
208
|
+
*/
|
|
209
|
+
Event.prototype.post = function(path, run, sort = 100) {
|
|
210
|
+
this.routes["post"].push(this.route_model({
|
|
211
|
+
method: "POST",
|
|
212
|
+
path,
|
|
213
|
+
sort
|
|
214
|
+
}, run));
|
|
215
|
+
this.route_sort('post');
|
|
216
|
+
};
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* 添加get路由
|
|
220
|
+
* @param {String} path 路由路径
|
|
221
|
+
* @param {Function} func 回调函数
|
|
222
|
+
* @param {Number} sort 排列顺序
|
|
223
|
+
*/
|
|
224
|
+
Event.prototype.get = function(path, run, sort = 100) {
|
|
225
|
+
this.routes["get"].push(this.route_model({
|
|
226
|
+
method: "GET",
|
|
227
|
+
path,
|
|
228
|
+
sort
|
|
229
|
+
}, run));
|
|
230
|
+
this.route_sort('get');
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* 请求前
|
|
235
|
+
* @param {String} target 目标
|
|
236
|
+
* @param {Function} func 回调函数
|
|
237
|
+
* @param {Number} sort 排列顺序
|
|
238
|
+
*/
|
|
239
|
+
Event.prototype.before = function(target, run, sort = 100) {
|
|
240
|
+
this.events["before"].push(this.event_model({
|
|
241
|
+
end: false,
|
|
242
|
+
target,
|
|
243
|
+
sort
|
|
244
|
+
}, run));
|
|
245
|
+
this.event_sort('before');
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
/**
|
|
249
|
+
* 请求后
|
|
250
|
+
* @param {String} target 目标
|
|
251
|
+
* @param {Function} func 回调函数
|
|
252
|
+
* @param {Number} sort 排列顺序
|
|
253
|
+
*/
|
|
254
|
+
Event.prototype.check = function(target, run, sort = 100) {
|
|
255
|
+
this.events["check"].push(this.event_model({
|
|
256
|
+
target,
|
|
257
|
+
sort
|
|
258
|
+
}, run));
|
|
259
|
+
this.event_sort('check');
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* 主要
|
|
264
|
+
* @param {String} target 目标
|
|
265
|
+
* @param {Function} func 回调函数
|
|
266
|
+
* @param {Number} sort 排列顺序
|
|
267
|
+
*/
|
|
268
|
+
Event.prototype.main = function(target, run, sort = 100) {
|
|
269
|
+
this.events["main"].push(this.event_model({
|
|
270
|
+
end: false,
|
|
271
|
+
target,
|
|
272
|
+
sort
|
|
273
|
+
}, run));
|
|
274
|
+
this.event_sort('main');
|
|
275
|
+
};
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* 渲染
|
|
279
|
+
* @param {String} target 目标
|
|
280
|
+
* @param {Function} func 回调函数
|
|
281
|
+
* @param {Number} sort 排列顺序
|
|
282
|
+
*/
|
|
283
|
+
Event.prototype.render = function(target, run, sort = 100) {
|
|
284
|
+
this.events["render"].push(this.event_model({
|
|
285
|
+
target,
|
|
286
|
+
sort
|
|
287
|
+
}, run));
|
|
288
|
+
this.event_sort('render');
|
|
289
|
+
};
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* 请求后
|
|
293
|
+
* @param {String} target 目标
|
|
294
|
+
* @param {Function} func 回调函数
|
|
295
|
+
* @param {Number} sort 排列顺序
|
|
296
|
+
*/
|
|
297
|
+
Event.prototype.after = function(target, run, sort = 100) {
|
|
298
|
+
this.events["after"].push(this.event_model({
|
|
299
|
+
end: false,
|
|
300
|
+
target,
|
|
301
|
+
sort
|
|
302
|
+
}, run));
|
|
303
|
+
this.event_sort('after');
|
|
304
|
+
};
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
/**
|
|
308
|
+
* 路由排序方式
|
|
309
|
+
* @param {Object} obj_a 对象A
|
|
310
|
+
* @param {Object} obj_b 对象B
|
|
311
|
+
*/
|
|
312
|
+
Event.prototype.route_sort_way = function(obj_a, obj_b) {
|
|
313
|
+
var a = obj_a.config;
|
|
314
|
+
var b = obj_b.config;
|
|
315
|
+
var n = a.sort - b.sort;
|
|
316
|
+
if (n == 0) {
|
|
317
|
+
return b.path.length - a.path.length;
|
|
318
|
+
} else {
|
|
319
|
+
return n;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* 路由排序
|
|
325
|
+
* @param {String} key 排序类型
|
|
326
|
+
*/
|
|
327
|
+
Event.prototype.route_sort = function(key) {
|
|
328
|
+
if (key) {
|
|
329
|
+
if (this.routes[key]) {
|
|
330
|
+
this.routes[key].sort(this.route_sort_way);
|
|
331
|
+
}
|
|
332
|
+
} else {
|
|
333
|
+
this.routes["post"].sort(this.route_sort_way);
|
|
334
|
+
this.routes["get"].sort(this.route_sort_way);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* 事件排序方式
|
|
340
|
+
* @param {Object} obj_a 对象A
|
|
341
|
+
* @param {Object} obj_b 对象B
|
|
342
|
+
*/
|
|
343
|
+
Event.prototype.event_sort_way = function(obj_a, obj_b) {
|
|
344
|
+
var a = obj_a.config;
|
|
345
|
+
var b = obj_b.config;
|
|
346
|
+
var n = a.sort - b.sort;
|
|
347
|
+
if (n == 0) {
|
|
348
|
+
return b.target.length - a.target.length;
|
|
349
|
+
} else {
|
|
350
|
+
return n;
|
|
351
|
+
}
|
|
352
|
+
};
|
|
353
|
+
|
|
354
|
+
/**
|
|
355
|
+
* 事件排序
|
|
356
|
+
* @param {String} key 排序类型
|
|
357
|
+
*/
|
|
358
|
+
Event.prototype.event_sort = function(key) {
|
|
359
|
+
if (key) {
|
|
360
|
+
if (this.events[key]) {
|
|
361
|
+
this.events[key].sort(this.event_sort_way);
|
|
362
|
+
}
|
|
363
|
+
} else {
|
|
364
|
+
this.events["before"].sort(this.event_sort_way);
|
|
365
|
+
this.events["check"].sort(this.event_sort_way);
|
|
366
|
+
this.events["main"].sort(this.event_sort_way);
|
|
367
|
+
this.events["render"].sort(this.event_sort_way);
|
|
368
|
+
this.events["after"].sort(this.event_sort_way);
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
|
|
372
|
+
/**
|
|
373
|
+
* 对象转移
|
|
374
|
+
* @param {Array} lt 排序类型
|
|
375
|
+
* @param {Array} list 排序类型
|
|
376
|
+
* @param {String} paths 路径集合
|
|
377
|
+
* @param {String} key 主键
|
|
378
|
+
*/
|
|
379
|
+
Event.prototype.shift = function(lt, list, paths, key = "target") {
|
|
380
|
+
for (var i = list.length - 1; i >= 0; i--) {
|
|
381
|
+
var o = list[i];
|
|
382
|
+
var p = o.config[key];
|
|
383
|
+
for (var n = 0; n < paths.length; n++) {
|
|
384
|
+
if (p.has(paths[n])) {
|
|
385
|
+
lt.push(o);
|
|
386
|
+
list.splice(i, 1);
|
|
387
|
+
};
|
|
388
|
+
}
|
|
389
|
+
}
|
|
390
|
+
};
|
|
391
|
+
|
|
392
|
+
/**
|
|
393
|
+
* 排序
|
|
394
|
+
* @param {String} key 排序类型
|
|
395
|
+
*/
|
|
396
|
+
Event.prototype.sort = function() {
|
|
397
|
+
this.event_sort();
|
|
398
|
+
this.route_sort();
|
|
399
|
+
};
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* 应用
|
|
403
|
+
* @param {Object} server 服务
|
|
404
|
+
* @param {Object} config 配置参数
|
|
405
|
+
*/
|
|
406
|
+
module.exports = function(server, config) {
|
|
407
|
+
"./app".fullname().addDir();
|
|
408
|
+
|
|
409
|
+
server = new Event(server, config);
|
|
410
|
+
return server;
|
|
411
|
+
};
|
|
@@ -0,0 +1,24 @@
|
|
|
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(proxy(options, function(op, ctx, next) {
|
|
17
|
+
if (ctx.session && ctx.session.user) {
|
|
18
|
+
ctx.request.header['user_id'] = ctx.session.user.user_id;
|
|
19
|
+
}
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return server;
|
|
24
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 应用
|
|
3
|
+
* @param {Object} server 服务
|
|
4
|
+
* @param {Object} config 配置参数
|
|
5
|
+
*/
|
|
6
|
+
module.exports = function(server, config) {
|
|
7
|
+
"./app".fullname().addDir();
|
|
8
|
+
|
|
9
|
+
// 追加主程序
|
|
10
|
+
server.main("/*", async (ctx, db) => {
|
|
11
|
+
var md = ctx.method.toLocaleLowerCase();
|
|
12
|
+
var list = server.routes[md];
|
|
13
|
+
return await server.run_route(ctx, db, list);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
// 使用路由(主要)
|
|
17
|
+
server.use(async (ctx, next) => {
|
|
18
|
+
var db = ctx.db;
|
|
19
|
+
if (ctx.path !== "/favicon.ico") {
|
|
20
|
+
db.ret = await server.run_event(ctx, server.events.check, db);
|
|
21
|
+
if (!db.ret) {
|
|
22
|
+
db.ret = await server.run_event(ctx, server.events.main, db);
|
|
23
|
+
}
|
|
24
|
+
db.ret = await server.run_event(ctx, server.events.render, db) || db.ret;
|
|
25
|
+
if (db.ret) {
|
|
26
|
+
ctx.body = db.ret;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
await next();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
return server;
|
|
33
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const websocket = require('koa-websocket');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 应用
|
|
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((ctx, next) => {
|
|
16
|
+
$.socket.run(ctx, next);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return server;
|
|
21
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const statics = require('mm_statics');
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* 应用
|
|
5
|
+
* @param {Object} server 服务
|
|
6
|
+
* @param {Object} config 配置参数
|
|
7
|
+
*/
|
|
8
|
+
module.exports = function(server, config) {
|
|
9
|
+
// 处理静态文件
|
|
10
|
+
if (config.static) {
|
|
11
|
+
server.use(statics(
|
|
12
|
+
config.static_path.fullname(), {
|
|
13
|
+
maxAge: 60 * 60 * 24 * 7,
|
|
14
|
+
gzip: true,
|
|
15
|
+
brotli: true
|
|
16
|
+
}));
|
|
17
|
+
// 使用多路径静态文件处理器
|
|
18
|
+
if ($.Static) {
|
|
19
|
+
const Static = $.Static;
|
|
20
|
+
$.static = new Static();
|
|
21
|
+
$.static.update();
|
|
22
|
+
server.use($.static.run);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
return server;
|
|
26
|
+
};
|