mm_os 3.3.1 → 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.
- package/LICENSE +21 -201
- package/README.md +491 -99
- package/README_EN.md +498 -0
- package/adapter/adapter.js +431 -0
- package/adapter/custom_persistence.js +660 -0
- package/adapter/mqtt.js +273 -0
- package/adapter/socket.js +113 -0
- package/adapter/web.js +67 -0
- package/adapter/websocket.js +146 -0
- package/com/api/com.json +5 -0
- package/{core/com → com}/api/config.tpl.json +8 -8
- package/com/api/drive.js +708 -0
- package/com/api/index.js +198 -0
- package/com/api/oauth.js +200 -0
- package/com/api/script.tpl.js +32 -0
- package/com/cmd/README.md +11 -0
- package/com/cmd/com.json +5 -0
- package/com/cmd/config.tpl.json +122 -0
- package/com/cmd/drive.js +1548 -0
- package/com/cmd/index.js +1066 -0
- package/com/cmd/msg.json +48 -0
- package/com/cmd/nlp.js +525 -0
- package/com/cmd/script.tpl.js +32 -0
- package/com/db/com.json +5 -0
- package/com/db/drive.js +1999 -0
- package/com/db/index.js +242 -0
- package/{core/com → com}/event/README.md +4 -4
- package/com/event/com.json +5 -0
- package/{core/com → com}/event/config.tpl.json +18 -18
- package/com/event/drive.js +59 -0
- package/com/event/index.js +409 -0
- package/com/event/script.tpl.js +23 -0
- package/com/mqtt/com.json +5 -0
- package/{core/com → com}/mqtt/config.tpl.json +3 -5
- package/com/mqtt/drive.js +676 -0
- package/com/mqtt/index.js +822 -0
- package/com/mqtt/mm_mqtt.js +425 -0
- package/com/mqtt/script.tpl.js +723 -0
- package/com/nav/com.json +5 -0
- package/com/nav/config.tpl.json +84 -0
- package/com/nav/drive.js +702 -0
- package/com/nav/index.js +231 -0
- package/{core/com → com}/nav/tpl/admin_pc/page_config.vue +280 -280
- package/{core/com → com}/nav/tpl/admin_pc/page_config_form.vue +194 -194
- package/com/nav/tpl/admin_pc/page_form.vue +180 -0
- package/com/nav/tpl/admin_pc/page_view.vue +124 -0
- package/com/nav/tpl/dev_pc/page_default.vue +247 -0
- package/com/nav/tpl/dev_pc/page_type.vue +313 -0
- package/com/nav/tpl/home_pc/page_default.vue +234 -0
- package/com/nav/tpl/home_pc/page_form.vue +137 -0
- package/com/nav/tpl/home_pc/page_list.vue +234 -0
- package/com/nav/tpl/home_pc/page_nav.vue +221 -0
- package/com/nav/tpl/home_pc/page_type.vue +234 -0
- package/com/nav/tpl/home_pc/page_view.vue +125 -0
- package/com/nav/tpl/home_phone/page_channel.vue +234 -0
- package/com/nav/tpl/home_phone/page_default.vue +234 -0
- package/com/nav/tpl/home_phone/page_form.vue +137 -0
- package/com/nav/tpl/home_phone/page_nav.vue +237 -0
- package/com/nav/tpl/home_phone/page_type.vue +234 -0
- package/com/nav/tpl/home_phone/page_view.vue +125 -0
- package/com/nav/viewmodel.js +446 -0
- package/com/param/com.json +5 -0
- package/{core/com → com}/param/config.tpl.json +7 -1
- package/com/param/drive.js +502 -0
- package/com/param/index.js +155 -0
- package/com/param/script.tpl.js +12 -0
- package/com/pendant/com.json +5 -0
- package/{core/com/component → com/pendant}/config.tpl.json +15 -13
- package/com/pendant/drive.js +204 -0
- package/com/pendant/index.js +441 -0
- package/com/pendant/pendant.html +16 -0
- package/com/pendant/script.tpl.js +18 -0
- package/com/socket/com.json +5 -0
- package/com/socket/config.tpl.json +12 -0
- package/com/socket/drive.js +651 -0
- package/com/socket/index.js +351 -0
- package/com/socket/script.tpl.js +41 -0
- package/com/sql/com.json +5 -0
- package/{core/com → com}/sql/config.tpl.json +13 -9
- package/com/sql/drive.js +1259 -0
- package/com/sql/index.js +150 -0
- package/com/sql/script.tpl.js +47 -0
- package/com/static/com.json +5 -0
- package/{core/com → com}/static/config.tpl.json +10 -6
- package/com/static/drive.js +194 -0
- package/com/static/index.js +226 -0
- package/com/static/script.tpl.js +28 -0
- package/com/task/com.json +5 -0
- package/{core/com → com}/task/config.tpl.json +4 -6
- package/com/task/drive.js +405 -0
- package/com/task/index.js +148 -0
- package/com/task/script.tpl.js +37 -0
- package/com/template/com.json +5 -0
- package/com/template/config.tpl.json +16 -0
- package/com/template/drive.js +80 -0
- package/com/template/index.js +141 -0
- package/com.js +156 -0
- package/common/README.md +2 -0
- package/common/handler/msg/handler.json +22 -0
- package/common/handler/msg/index.js +23 -0
- package/common/handler/player/handler.json +22 -0
- package/common/handler/player/index.js +287 -0
- package/common/handler/user/handler.json +22 -0
- package/common/handler/user/index.js +23 -0
- package/common/middleware/web_after/index.js +29 -0
- package/common/middleware/web_after/middleware.json +9 -0
- package/common/middleware/web_base/index.js +113 -0
- package/common/middleware/web_base/middleware.json +19 -0
- package/common/middleware/web_before/index.js +33 -0
- package/common/middleware/web_before/middleware.json +9 -0
- package/common/middleware/web_cors/index.js +87 -0
- package/common/middleware/web_cors/middleware.json +24 -0
- package/common/middleware/web_error/index.js +119 -0
- package/common/middleware/web_error/middleware.json +18 -0
- package/common/middleware/web_ip/index.js +15 -0
- package/common/middleware/web_ip/middleware.json +14 -0
- package/common/middleware/web_logger/index.js +156 -0
- package/common/middleware/web_logger/middleware.json +14 -0
- package/common/middleware/web_main/index.js +24 -0
- package/common/middleware/web_main/middleware.json +9 -0
- package/common/middleware/web_static/index.js +73 -0
- package/common/middleware/web_static/middleware.json +54 -0
- package/common/middleware/web_waf/index.js +385 -0
- package/common/middleware/web_waf/middleware.json +13 -0
- package/common/model/msg/index.js +88 -0
- package/common/model/msg/model.json +401 -0
- package/common/model/player/index.js +63 -0
- package/common/model/player/model.json +185 -0
- package/common/model/user/index.js +11 -0
- package/common/model/user/model.json +219 -0
- package/core/app/config.tpl.json +67 -0
- package/core/app/index.js +632 -0
- package/core/app/script.tpl.js +52 -0
- package/core/channel/index.js +899 -0
- package/core/channel/matcher.js +585 -0
- package/core/com/config.tpl.json +16 -0
- package/core/com/index.js +74 -0
- package/core/com/script.tpl.js +5 -0
- package/core/component/component.js +42 -0
- package/core/component/config.tpl.json +63 -0
- package/core/component/index.js +273 -0
- package/core/component/script.tpl.js +19 -0
- package/core/controller/config.tpl.json +14 -0
- package/core/controller/index.js +373 -0
- package/core/controller/script.tpl.js +27 -0
- package/core/factory/config.tpl.json +14 -0
- package/core/factory/entity.js +275 -0
- package/core/factory/index.js +241 -0
- package/core/factory/script.tpl.js +16 -0
- package/core/game/bat/index.js +137 -0
- package/core/game/bat/world.js +622 -0
- package/core/game/config.tpl.json +16 -0
- package/core/game/entity_admin.js +230 -0
- package/core/game/index.js +186 -0
- package/core/handler/config.tpl.json +22 -0
- package/core/handler/index.js +181 -0
- package/core/handler/script.tpl.js +23 -0
- package/core/logic/config.tpl.json +14 -0
- package/core/logic/index.js +59 -0
- package/core/logic/script.tpl.js +19 -0
- package/core/middleware/config.tpl.json +16 -0
- package/core/middleware/index.js +125 -0
- package/core/middleware/script.tpl.js +37 -0
- package/core/mod/config.tpl.json +22 -0
- package/core/mod/index.js +130 -0
- package/core/mod/script.tpl.js +34 -0
- package/core/model/config.tpl.json +219 -0
- package/core/model/index.js +272 -0
- package/core/model/model.js +27 -0
- package/core/model/script.tpl.js +20 -0
- package/core/notifier/config.tpl.json +14 -0
- package/core/notifier/index.js +77 -0
- package/core/notifier/script.tpl.js +20 -0
- package/core/plugin/config.tpl.json +24 -0
- package/core/plugin/index.js +232 -0
- package/core/plugin/script.tpl.js +51 -0
- package/core/pusher/config.tpl.json +14 -0
- package/core/pusher/index.js +161 -0
- package/core/pusher/script.tpl.js +20 -0
- package/core/room/bat/index.js +170 -0
- package/core/room/bat/room.js +524 -0
- package/core/room/config.tpl.json +20 -0
- package/core/room/index.js +249 -0
- package/core/room/room.js +61 -0
- package/core/scene/config.tpl.json +14 -0
- package/core/scene/index.js +466 -0
- package/core/scene/loop.js +1255 -0
- package/core/scene/map.js +28 -0
- package/core/scene/script.tpl.js +22 -0
- package/core/sender/config.tpl.json +14 -0
- package/core/sender/index.js +79 -0
- package/core/sender/script.tpl.js +20 -0
- package/core/service/config.tpl.json +14 -0
- package/core/service/index.js +100 -0
- package/core/service/script.tpl.js +25 -0
- package/core/store/config.tpl.json +26 -0
- package/core/store/index.js +1755 -0
- package/core/store/script.tpl.js +22 -0
- package/core/store/sql.js +1464 -0
- package/core/system/config.tpl.json +18 -0
- package/core/system/index.js +312 -0
- package/core/system/script.tpl.js +77 -0
- package/core/view/config.tpl.json +14 -0
- package/core/view/index.js +91 -0
- package/core/view/script.tpl.js +20 -0
- package/core/zone/bat/index.js +725 -0
- package/core/zone/config.tpl.json +54 -0
- package/core/zone/index.js +614 -0
- package/core/zone/script.tpl.js +10 -0
- package/core/zone/zone_bat.js +136 -0
- package/core//345/237/272/347/261/273/346/250/241/345/235/227/346/270/205/345/215/225.md +24 -0
- package/index.js +17 -333
- package/os.js +57 -0
- package/package.json +58 -58
- package/server.js +598 -0
- package/README.en.md +0 -36
- package/conf.json +0 -3
- package/core/base/mqtt/index.js +0 -1110
- package/core/base/mqtt/lib.js +0 -40
- package/core/base/web/index.js +0 -245
- package/core/com/api/com.json +0 -4
- package/core/com/api/drive.js +0 -668
- package/core/com/api/index.js +0 -108
- package/core/com/api/oauth.js +0 -158
- package/core/com/api/script.js +0 -32
- package/core/com/app/README.md +0 -3
- package/core/com/app/com.json +0 -4
- package/core/com/app/config.tpl.json +0 -16
- package/core/com/app/drive.js +0 -309
- package/core/com/app/index.js +0 -211
- package/core/com/app/script.js +0 -155
- package/core/com/cmd/com.json +0 -4
- package/core/com/cmd/config.tpl.json +0 -66
- package/core/com/cmd/drive.js +0 -513
- package/core/com/cmd/index.js +0 -354
- package/core/com/cmd/old/5w2h.js +0 -54
- package/core/com/cmd/old/drive.js +0 -423
- package/core/com/cmd/script.js +0 -11
- package/core/com/component/README.md +0 -3
- package/core/com/component/com.json +0 -4
- package/core/com/component/component.html +0 -16
- package/core/com/component/drive.js +0 -197
- package/core/com/component/index.js +0 -312
- package/core/com/component/script.js +0 -18
- package/core/com/db/com.json +0 -4
- package/core/com/db/drive.js +0 -1160
- package/core/com/db/index.js +0 -176
- package/core/com/event/com.json +0 -4
- package/core/com/event/drive.js +0 -133
- package/core/com/event/index.js +0 -345
- package/core/com/event/script.js +0 -26
- package/core/com/eventer/com.js +0 -477
- package/core/com/eventer/com.json +0 -4
- package/core/com/middleware/com.js +0 -154
- package/core/com/middleware/com.json +0 -4
- package/core/com/middleware/config.tpl.json +0 -8
- package/core/com/middleware/script.js +0 -9
- package/core/com/mqtt/com.json +0 -4
- package/core/com/mqtt/drive.js +0 -600
- package/core/com/mqtt/index.js +0 -572
- package/core/com/mqtt/mm_mqtt.js +0 -330
- package/core/com/mqtt/script.js +0 -604
- package/core/com/msg/com.js +0 -296
- package/core/com/msg/com.json +0 -4
- package/core/com/nav/com.json +0 -4
- package/core/com/nav/config.tpl.json +0 -75
- package/core/com/nav/drive.js +0 -549
- package/core/com/nav/index.js +0 -182
- package/core/com/nav/tpl/admin_pc/page_form.vue +0 -180
- package/core/com/nav/tpl/admin_pc/page_view.vue +0 -124
- package/core/com/nav/tpl/dev_pc/page_default.vue +0 -247
- package/core/com/nav/tpl/dev_pc/page_type.vue +0 -313
- package/core/com/nav/tpl/home_pc/page_default.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_form.vue +0 -137
- package/core/com/nav/tpl/home_pc/page_list.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_nav.vue +0 -221
- package/core/com/nav/tpl/home_pc/page_type.vue +0 -234
- package/core/com/nav/tpl/home_pc/page_view.vue +0 -125
- package/core/com/nav/tpl/home_phone/page_channel.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_default.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_form.vue +0 -137
- package/core/com/nav/tpl/home_phone/page_nav.vue +0 -237
- package/core/com/nav/tpl/home_phone/page_type.vue +0 -234
- package/core/com/nav/tpl/home_phone/page_view.vue +0 -125
- package/core/com/nav/viewmodel.js +0 -296
- package/core/com/param/drive.js +0 -366
- package/core/com/param/index.js +0 -80
- package/core/com/param/script.js +0 -12
- package/core/com/param/test.js +0 -98
- package/core/com/plugin/README.md +0 -3
- package/core/com/plugin/com.json +0 -4
- package/core/com/plugin/config.tpl.json +0 -26
- package/core/com/plugin/drive.js +0 -536
- package/core/com/plugin/index.js +0 -259
- package/core/com/plugin/script.js +0 -213
- package/core/com/rpc/com.json +0 -4
- package/core/com/rpc/drive.js +0 -160
- package/core/com/rpc/index.js +0 -87
- package/core/com/rpc/rpc.js +0 -118
- package/core/com/socket/com.json +0 -4
- package/core/com/socket/config.tpl.json +0 -14
- package/core/com/socket/drive.js +0 -403
- package/core/com/socket/index.js +0 -62
- package/core/com/socket/script.js +0 -42
- package/core/com/sql/drive.js +0 -1087
- package/core/com/sql/index.js +0 -83
- package/core/com/sql/script.js +0 -48
- package/core/com/static/com.json +0 -4
- package/core/com/static/drive.js +0 -220
- package/core/com/static/index.js +0 -149
- package/core/com/static/script.js +0 -28
- package/core/com/task/com.json +0 -4
- package/core/com/task/drive.js +0 -403
- package/core/com/task/index.js +0 -110
- package/core/com/task/script.js +0 -37
- package/core/com/timer/com.js +0 -217
- package/core/com/timer/com.json +0 -4
- package/core/com/tpl/com.js +0 -19
- package/core/com/tpl/com.json +0 -4
- package/lib/actions.js +0 -50
- package/lib/base.js +0 -361
- package/lib/com.js +0 -29
- package/lib/ref.js +0 -121
- package/middleware/cors/index.js +0 -119
- package/middleware/cors/middleware.json +0 -20
- package/middleware/csrf/index.js +0 -202
- package/middleware/csrf/middleware.json +0 -24
- package/middleware/ip_firewall/index.js +0 -476
- package/middleware/ip_firewall/middleware.json +0 -109
- package/middleware/mqtt_base/index.js +0 -10
- package/middleware/mqtt_base/middleware.json +0 -11
- package/middleware/security_audit/index.js +0 -543
- package/middleware/security_audit/middleware.json +0 -48
- package/middleware/waf/index.js +0 -343
- package/middleware/waf/middleware.json +0 -10
- package/middleware/waf_ddos/index.js +0 -520
- package/middleware/waf_ddos/middleware.json +0 -38
- package/middleware/waf_xss/index.js +0 -269
- package/middleware/waf_xss/middleware.json +0 -18
- package/middleware/web_after/index.js +0 -33
- package/middleware/web_after/middleware.json +0 -10
- package/middleware/web_base/index.js +0 -90
- package/middleware/web_base/middleware.json +0 -10
- package/middleware/web_before/index.js +0 -27
- package/middleware/web_before/middleware.json +0 -10
- package/middleware/web_check/index.js +0 -28
- package/middleware/web_check/middleware.json +0 -10
- package/middleware/web_main/index.js +0 -28
- package/middleware/web_main/middleware.json +0 -10
- package/middleware/web_proxy/index.js +0 -37
- package/middleware/web_proxy/middleware.json +0 -10
- package/middleware/web_render/index.js +0 -87
- package/middleware/web_render/middleware.json +0 -10
- package/middleware/web_socket/index.js +0 -34
- package/middleware/web_socket/middleware.json +0 -10
- package/middleware/web_static/index.js +0 -115
- package/middleware/web_static/middleware.json +0 -10
- /package/{core/com → com}/api/README.md +0 -0
- /package/{core/com → com}/db/README.md +0 -0
- /package/{core/com → com}/mqtt/README.md +0 -0
- /package/{core/com → com}/nav/README.md +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_default.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_lang.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/admin_pc/page_type.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_config.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_form.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_nav.vue +0 -0
- /package/{core/com → com}/nav/tpl/dev_pc/page_table.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_pc/page_channel.vue +0 -0
- /package/{core/com → com}/nav/tpl/home_phone/page_list.vue +0 -0
- /package/{core/com → com}/param/README.md +0 -0
- /package/{core/com/cmd → com/pendant}/README.md +0 -0
- /package/{core/com → com}/socket/README.md +0 -0
- /package/{core/com → com}/sql/README.md +0 -0
- /package/{core/com → com}/static/README.md +0 -0
- /package/{core/com → com}/task/README.md +0 -0
package/README_EN.md
ADDED
|
@@ -0,0 +1,498 @@
|
|
|
1
|
+
# MOS Server Architecture
|
|
2
|
+
|
|
3
|
+
[](https://badge.fury.io/js/mm_os)
|
|
4
|
+
[](https://www.npmjs.com/package/mm_os)
|
|
5
|
+
[](https://gitee.com/qiuwenwu91/mm_os/blob/master/LICENSE)
|
|
6
|
+
|
|
7
|
+
## Project Introduction
|
|
8
|
+
|
|
9
|
+
MOS is a lightweight server architecture that provides a complete server development framework, including support for multiple communication protocols such as Web, WebSocket, MQTT, Socket, as well as rich components and modules.
|
|
10
|
+
|
|
11
|
+
Suitable for quickly building websites, mini-program backends, AI applications, IoT applications, and small-to-medium game servers.
|
|
12
|
+
|
|
13
|
+
## Core Features
|
|
14
|
+
|
|
15
|
+
- **Multi-protocol support**: Web, WebSocket, MQTT, Socket
|
|
16
|
+
- **Modular design**: Application, Module, Middleware, Notifier, Sender, Pusher
|
|
17
|
+
- **Infrastructure**: Database, Cache, Log, File Management
|
|
18
|
+
- **Event-driven**: Asynchronous processing based on event bus
|
|
19
|
+
- **Plugin system**: Support for function extension
|
|
20
|
+
|
|
21
|
+
## Design Philosophy: Configuration and Logic Separation
|
|
22
|
+
|
|
23
|
+
The core design principle of MOS framework is **separation of configuration and logic**. Both `core` modules and `com` components follow a unified structure:
|
|
24
|
+
|
|
25
|
+
### Module Composition
|
|
26
|
+
|
|
27
|
+
Each module consists of the following files:
|
|
28
|
+
|
|
29
|
+
| File Type | File Name | Purpose |
|
|
30
|
+
|-----------|-----------|---------|
|
|
31
|
+
| **Configuration** | `config.tpl.json` / `com.json` | Declarative definition of module configuration and metadata |
|
|
32
|
+
| **Logic** | `index.js` / `script.tpl.js` | Implementation of business logic and functionality |
|
|
33
|
+
| **Driver** | `drive.js` (optional) | Protocol driver and adapter logic |
|
|
34
|
+
|
|
35
|
+
### Design Advantages
|
|
36
|
+
|
|
37
|
+
**1. Declarative Configuration**
|
|
38
|
+
- JSON files define module metadata and configuration declaratively
|
|
39
|
+
- Module registration and parameter configuration can be completed without writing code
|
|
40
|
+
- Easy to manage and configure through visual tools
|
|
41
|
+
|
|
42
|
+
**2. Logic and Configuration Decoupling**
|
|
43
|
+
- Configuration changes do not require code modification, reducing maintenance costs
|
|
44
|
+
- The same business logic can be reused with different configurations
|
|
45
|
+
- Configuration files can be independently version-managed and deployed
|
|
46
|
+
|
|
47
|
+
**3. Automation Capabilities**
|
|
48
|
+
- Framework can automatically scan JSON configurations for module registration
|
|
49
|
+
- Automatically generate documentation and configuration forms
|
|
50
|
+
- Automatically perform parameter validation, reducing repetitive code
|
|
51
|
+
|
|
52
|
+
**4. Hot Update Support**
|
|
53
|
+
- Configuration files can be hot-updated without restarting the service
|
|
54
|
+
- Supports dynamic addition/modification of module configurations
|
|
55
|
+
|
|
56
|
+
**5. Team Collaboration Optimization**
|
|
57
|
+
- Configuration personnel and developers can work in parallel
|
|
58
|
+
- Non-developers can also participate in module configuration
|
|
59
|
+
- Unified configuration format reduces communication costs
|
|
60
|
+
|
|
61
|
+
### Module Types
|
|
62
|
+
|
|
63
|
+
**core modules**: Framework base modules including app, controller, model, logic, plugin, service, view, middleware, etc.
|
|
64
|
+
|
|
65
|
+
**com components**: Reusable common components including sql, cache, api, event, task, static, template, MQTT, Socket, etc.
|
|
66
|
+
|
|
67
|
+
## Quick Start
|
|
68
|
+
|
|
69
|
+
### Installation
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm install mm_os
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
### Basic Usage
|
|
76
|
+
|
|
77
|
+
```javascript
|
|
78
|
+
const { MM_os } = require('mm_os');
|
|
79
|
+
|
|
80
|
+
// Set runtime path
|
|
81
|
+
$.run_path = __dirname;
|
|
82
|
+
|
|
83
|
+
// Create server instance
|
|
84
|
+
const server = new MM_os({
|
|
85
|
+
web: {
|
|
86
|
+
host: '0.0.0.0',
|
|
87
|
+
port: 8000,
|
|
88
|
+
socket: true
|
|
89
|
+
},
|
|
90
|
+
mysql: {
|
|
91
|
+
host: '127.0.0.1',
|
|
92
|
+
port: 3306,
|
|
93
|
+
user: 'root',
|
|
94
|
+
password: '123456',
|
|
95
|
+
database: 'test'
|
|
96
|
+
},
|
|
97
|
+
cache: {
|
|
98
|
+
way: 'memory'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
// Start server
|
|
103
|
+
async function startServer() {
|
|
104
|
+
await server.init();
|
|
105
|
+
await server.start();
|
|
106
|
+
console.log('Server started successfully');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
startServer();
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Project Directory Structure
|
|
113
|
+
|
|
114
|
+
Projects developed with MOS framework follow a standardized directory structure:
|
|
115
|
+
|
|
116
|
+
```
|
|
117
|
+
├── app/ # Application directory containing multiple apps
|
|
118
|
+
│ ├── app_name/ # Application name
|
|
119
|
+
│ │ ├── event_api/ # Event API directory
|
|
120
|
+
│ │ │ ├── web/ # Web route handling
|
|
121
|
+
│ │ │ │ ├── event.json # Event configuration
|
|
122
|
+
│ │ │ │ └── main.js # Entry file
|
|
123
|
+
│ │ │ ├── api/ # API route
|
|
124
|
+
│ │ │ ├── client/ # Client API route
|
|
125
|
+
│ │ │ └── manage/ # Management backend route
|
|
126
|
+
│ │ ├── plugin/ # Plugin directory
|
|
127
|
+
│ │ │ ├── main/ # Main plugins (business logic)
|
|
128
|
+
│ │ │ │ └── api_{app}_{channel}/{api_name}/
|
|
129
|
+
│ │ │ │ ├── api.json # API configuration
|
|
130
|
+
│ │ │ │ ├── param.json # Parameter validation config
|
|
131
|
+
│ │ │ │ └── index.js # API implementation
|
|
132
|
+
│ │ │ └── server/ # Server plugins (data management)
|
|
133
|
+
│ │ ├── pendant/ # Pendant component directory
|
|
134
|
+
│ │ ├── static/ # Static resources
|
|
135
|
+
│ │ ├── app.json # Application configuration
|
|
136
|
+
│ │ └── index.js # Application entry
|
|
137
|
+
├── cache/ # Cache configuration directory
|
|
138
|
+
├── com/ # Common components directory
|
|
139
|
+
├── config/ # Global configuration directory
|
|
140
|
+
│ ├── local.json # Local configuration
|
|
141
|
+
│ ├── development.json # Development configuration
|
|
142
|
+
│ └── production.json # Production configuration
|
|
143
|
+
├── db/ # Database files directory (SQLite, etc.)
|
|
144
|
+
├── static/ # Global static resources
|
|
145
|
+
├── index.js # Project entry
|
|
146
|
+
└── config.json # Main configuration file
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Application Development
|
|
150
|
+
|
|
151
|
+
### Create Application
|
|
152
|
+
|
|
153
|
+
Each application contains independent business logic. Application configuration file `app.json`:
|
|
154
|
+
|
|
155
|
+
```json
|
|
156
|
+
{
|
|
157
|
+
"name": "user",
|
|
158
|
+
"version": "1.0",
|
|
159
|
+
"title": "User",
|
|
160
|
+
"description": "User authentication service",
|
|
161
|
+
"author": "developer",
|
|
162
|
+
"scope": "server",
|
|
163
|
+
"main": "./index.js",
|
|
164
|
+
"func_name": "main",
|
|
165
|
+
"sort": 10,
|
|
166
|
+
"state": 1,
|
|
167
|
+
"sql": {
|
|
168
|
+
"way": "mysql",
|
|
169
|
+
"mysql": {
|
|
170
|
+
"host": "127.0.0.1",
|
|
171
|
+
"port": 3306,
|
|
172
|
+
"user": "root",
|
|
173
|
+
"password": "password",
|
|
174
|
+
"database": "example"
|
|
175
|
+
}
|
|
176
|
+
},
|
|
177
|
+
"cache": {
|
|
178
|
+
"way": "redis"
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Event Route Configuration (event.json)
|
|
184
|
+
|
|
185
|
+
Define application routing rules:
|
|
186
|
+
|
|
187
|
+
```json
|
|
188
|
+
{
|
|
189
|
+
"/api/user/list": {
|
|
190
|
+
"method": "GET",
|
|
191
|
+
"title": "Get User List",
|
|
192
|
+
"auth": false
|
|
193
|
+
},
|
|
194
|
+
"/api/user/create": {
|
|
195
|
+
"method": "POST",
|
|
196
|
+
"title": "Create User",
|
|
197
|
+
"auth": true
|
|
198
|
+
},
|
|
199
|
+
"/user/*": {
|
|
200
|
+
"method": "ALL",
|
|
201
|
+
"title": "User Page Routes",
|
|
202
|
+
"auth": false
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
```
|
|
206
|
+
|
|
207
|
+
### Create API Interface
|
|
208
|
+
|
|
209
|
+
API is the core component of MOS framework. Each API consists of three files:
|
|
210
|
+
|
|
211
|
+
#### 1. api.json - API Configuration
|
|
212
|
+
|
|
213
|
+
```json
|
|
214
|
+
{
|
|
215
|
+
"name": "user_sign_in",
|
|
216
|
+
"title": "User Login",
|
|
217
|
+
"description": "User login interface, supports username/password, phone/code, and social login",
|
|
218
|
+
"path": "/api/user/sign_in",
|
|
219
|
+
"type": "api",
|
|
220
|
+
"method": "ALL",
|
|
221
|
+
"cache": 0,
|
|
222
|
+
"param_path": "./param.json",
|
|
223
|
+
"check_param": true,
|
|
224
|
+
"sort": 1
|
|
225
|
+
}
|
|
226
|
+
```
|
|
227
|
+
|
|
228
|
+
**api.json Field Description:**
|
|
229
|
+
|
|
230
|
+
| Field | Type | Required | Description |
|
|
231
|
+
|-------|------|----------|-------------|
|
|
232
|
+
| name | string | Yes | Unique API identifier |
|
|
233
|
+
| title | string | Yes | Display name |
|
|
234
|
+
| description | string | No | Description |
|
|
235
|
+
| path | string | Yes | Access path |
|
|
236
|
+
| type | string | Yes | Type, fixed as "api" |
|
|
237
|
+
| method | string | Yes | HTTP method: GET, POST, ALL |
|
|
238
|
+
| cache | number | No | Cache time in seconds, 0 means no cache |
|
|
239
|
+
| param_path | string | No | Parameter validation config path |
|
|
240
|
+
| check_param | boolean | No | Whether to validate parameters |
|
|
241
|
+
| sort | number | No | Sort order |
|
|
242
|
+
|
|
243
|
+
#### 2. param.json - Parameter Validation Configuration
|
|
244
|
+
|
|
245
|
+
```json
|
|
246
|
+
{
|
|
247
|
+
"title": "User Login Validation Model",
|
|
248
|
+
"name": "user_sign_in",
|
|
249
|
+
"filter": true,
|
|
250
|
+
"get": {
|
|
251
|
+
"query": ["account", "password", "code"],
|
|
252
|
+
"query_required": ["account"]
|
|
253
|
+
},
|
|
254
|
+
"post": {
|
|
255
|
+
"body": ["account", "password", "code", "phone"],
|
|
256
|
+
"body_required": ["account"]
|
|
257
|
+
},
|
|
258
|
+
"list": [
|
|
259
|
+
{
|
|
260
|
+
"name": "account",
|
|
261
|
+
"title": "Account",
|
|
262
|
+
"type": "string",
|
|
263
|
+
"string": {
|
|
264
|
+
"min": 5,
|
|
265
|
+
"max": 16,
|
|
266
|
+
"format": "username"
|
|
267
|
+
}
|
|
268
|
+
},
|
|
269
|
+
{
|
|
270
|
+
"name": "password",
|
|
271
|
+
"title": "Password",
|
|
272
|
+
"type": "string",
|
|
273
|
+
"string": {
|
|
274
|
+
"min": 32,
|
|
275
|
+
"max": 32,
|
|
276
|
+
"format": "password"
|
|
277
|
+
}
|
|
278
|
+
},
|
|
279
|
+
{
|
|
280
|
+
"name": "phone",
|
|
281
|
+
"title": "Phone Number",
|
|
282
|
+
"type": "string",
|
|
283
|
+
"string": {
|
|
284
|
+
"format": "phone",
|
|
285
|
+
"range": [11, 11]
|
|
286
|
+
}
|
|
287
|
+
},
|
|
288
|
+
{
|
|
289
|
+
"name": "code",
|
|
290
|
+
"title": "Verification Code",
|
|
291
|
+
"type": "string"
|
|
292
|
+
}
|
|
293
|
+
]
|
|
294
|
+
}
|
|
295
|
+
```
|
|
296
|
+
|
|
297
|
+
**param.json Field Description:**
|
|
298
|
+
|
|
299
|
+
| Field | Type | Description |
|
|
300
|
+
|-------|------|-------------|
|
|
301
|
+
| title | string | Validation model name |
|
|
302
|
+
| name | string | Model identifier |
|
|
303
|
+
| filter | boolean | Whether to enable filtering |
|
|
304
|
+
| get.query | array | Acceptable query parameters for GET |
|
|
305
|
+
| get.query_required | array | Required parameters for GET |
|
|
306
|
+
| post.body | array | Acceptable body parameters for POST |
|
|
307
|
+
| post.body_required | array | Required parameters for POST |
|
|
308
|
+
| list | array | Parameter validation rules |
|
|
309
|
+
|
|
310
|
+
**Supported Parameter Types:**
|
|
311
|
+
- `string`: String type, supports format (phone, email, username, password), min, max, range
|
|
312
|
+
- `number`: Number type, supports min, max, range
|
|
313
|
+
- `boolean`: Boolean type
|
|
314
|
+
- `array`: Array type
|
|
315
|
+
- `object`: Object type
|
|
316
|
+
|
|
317
|
+
#### 3. index.js - API Implementation
|
|
318
|
+
|
|
319
|
+
```javascript
|
|
320
|
+
/**
|
|
321
|
+
* User Login API
|
|
322
|
+
* @param {Object} ctx HTTP context
|
|
323
|
+
* @param {Object} db Data manager
|
|
324
|
+
* @return {Object} Execution result
|
|
325
|
+
*/
|
|
326
|
+
async function main(ctx, db) {
|
|
327
|
+
// Get request parameters
|
|
328
|
+
var params = ctx.method === "POST" ? ctx.request.body : ctx.request.query;
|
|
329
|
+
|
|
330
|
+
// Validate parameters
|
|
331
|
+
var account = params['account'];
|
|
332
|
+
var password = params['password'];
|
|
333
|
+
|
|
334
|
+
if (!account) {
|
|
335
|
+
return { code: 30001, message: 'Account cannot be empty' };
|
|
336
|
+
}
|
|
337
|
+
if (!password) {
|
|
338
|
+
return { code: 30002, message: 'Password cannot be empty' };
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
// Query user
|
|
342
|
+
db.table = "user_account";
|
|
343
|
+
db.key = "user_id";
|
|
344
|
+
var users = await db.get({ username: account });
|
|
345
|
+
|
|
346
|
+
if (users.length === 0) {
|
|
347
|
+
return { code: 60001, message: 'User does not exist' };
|
|
348
|
+
}
|
|
349
|
+
|
|
350
|
+
var user = users[0];
|
|
351
|
+
|
|
352
|
+
// Validate password
|
|
353
|
+
var pass = (password + user.salt).md5();
|
|
354
|
+
if (pass !== user.password) {
|
|
355
|
+
return { code: 30003, message: 'Incorrect password' };
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Set login state
|
|
359
|
+
ctx.session.user = user;
|
|
360
|
+
|
|
361
|
+
// Return result
|
|
362
|
+
return {
|
|
363
|
+
code: 200,
|
|
364
|
+
message: 'Login successful',
|
|
365
|
+
data: {
|
|
366
|
+
user_id: user.user_id,
|
|
367
|
+
username: user.username,
|
|
368
|
+
nickname: user.nickname
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
|
|
373
|
+
exports.main = main;
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Event Handler Entry (main.js)
|
|
377
|
+
|
|
378
|
+
```javascript
|
|
379
|
+
// Use API manager
|
|
380
|
+
var api = $.admin.api('user_web', 'Website - User Management');
|
|
381
|
+
api.call('update');
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* @description Main handler function
|
|
385
|
+
* @param {Object} ctx HTTP context
|
|
386
|
+
* @param {Object} db Data manager
|
|
387
|
+
* @return {Object} Execution result
|
|
388
|
+
*/
|
|
389
|
+
async function main(ctx, db) {
|
|
390
|
+
// Set database connection
|
|
391
|
+
$.push(db, $.admin.sql('sys').db(), true);
|
|
392
|
+
|
|
393
|
+
// Use template engine
|
|
394
|
+
db.tpl = new $.Tpl();
|
|
395
|
+
var bag = db.tpl.viewBag;
|
|
396
|
+
bag.path = ctx.path;
|
|
397
|
+
bag.query = ctx.query;
|
|
398
|
+
|
|
399
|
+
// Execute API routing
|
|
400
|
+
return await api.run(ctx, db);
|
|
401
|
+
}
|
|
402
|
+
|
|
403
|
+
exports.main = main;
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
## Configuration
|
|
407
|
+
|
|
408
|
+
MOS supports multiple configuration options:
|
|
409
|
+
|
|
410
|
+
- **web**: Web server configuration
|
|
411
|
+
- **mysql**: MySQL database configuration
|
|
412
|
+
- **sqlite**: SQLite database configuration
|
|
413
|
+
- **cache**: Cache configuration (`way` specifies type: `memory`, `redis`, `mongodb`)
|
|
414
|
+
- **redis**: Redis cache configuration
|
|
415
|
+
- **mongodb**: MongoDB configuration
|
|
416
|
+
- **mqtt**: MQTT server configuration
|
|
417
|
+
- **socket**: Socket server configuration
|
|
418
|
+
|
|
419
|
+
### Configuration File Example
|
|
420
|
+
|
|
421
|
+
```json
|
|
422
|
+
{
|
|
423
|
+
"name": "mos",
|
|
424
|
+
"title": "Server System",
|
|
425
|
+
"log": {
|
|
426
|
+
"level": "debug",
|
|
427
|
+
"file": true
|
|
428
|
+
},
|
|
429
|
+
"web": {
|
|
430
|
+
"state": true,
|
|
431
|
+
"host": "0.0.0.0",
|
|
432
|
+
"port": 8000,
|
|
433
|
+
"socket": false,
|
|
434
|
+
"cos": {
|
|
435
|
+
"status": true,
|
|
436
|
+
"origin": "*"
|
|
437
|
+
},
|
|
438
|
+
"static": {
|
|
439
|
+
"state": 1,
|
|
440
|
+
"root": "./static"
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
"mysql": {
|
|
444
|
+
"host": "127.0.0.1",
|
|
445
|
+
"port": 3306,
|
|
446
|
+
"user": "root",
|
|
447
|
+
"password": "password",
|
|
448
|
+
"database": "example"
|
|
449
|
+
},
|
|
450
|
+
"cache": {
|
|
451
|
+
"way": "redis"
|
|
452
|
+
},
|
|
453
|
+
"redis": {
|
|
454
|
+
"host": "localhost",
|
|
455
|
+
"port": 6379,
|
|
456
|
+
"password": "",
|
|
457
|
+
"database": 0
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
```
|
|
461
|
+
|
|
462
|
+
## Global Objects
|
|
463
|
+
|
|
464
|
+
MOS provides rich global objects for development:
|
|
465
|
+
|
|
466
|
+
### `$` Object
|
|
467
|
+
|
|
468
|
+
| Property | Description |
|
|
469
|
+
|----------|-------------|
|
|
470
|
+
| `$.sql` | Database operation object |
|
|
471
|
+
| `$.cache` | Cache operation object |
|
|
472
|
+
| `$.log` | Log object |
|
|
473
|
+
| `$.admin` | Admin object |
|
|
474
|
+
| `$.eventer` | Event bus |
|
|
475
|
+
| `$.config` | Configuration manager |
|
|
476
|
+
| `$.Tpl` | Template engine class |
|
|
477
|
+
| `$.ret` | Response utility |
|
|
478
|
+
| `$.run_path` | Current runtime path |
|
|
479
|
+
|
|
480
|
+
### `$.ret` Response Utility
|
|
481
|
+
|
|
482
|
+
```javascript
|
|
483
|
+
// Success response
|
|
484
|
+
return $.ret.body(data); // { code: 200, message: 'success', data: data }
|
|
485
|
+
|
|
486
|
+
// Error response
|
|
487
|
+
return $.ret.error(code, message); // { code: code, message: message }
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
## Development Guide
|
|
491
|
+
|
|
492
|
+
1. **Install dependencies**: `npm install`
|
|
493
|
+
2. **Development and debugging**: `npm run dev`
|
|
494
|
+
3. **Run tests**: `npm run test`
|
|
495
|
+
|
|
496
|
+
## License
|
|
497
|
+
|
|
498
|
+
ISC
|