chanjs 1.0.13 → 1.0.14

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/core/chan.js CHANGED
@@ -3,7 +3,7 @@ const config = require("./lib/config/config.js");
3
3
  const path = require("path");
4
4
  const fs = require("fs");
5
5
  const core = require("./lib/core.js");
6
-
6
+ const cors = require('cors')
7
7
  /**
8
8
  * @description 基于express封装的mvc框架,遵循约定优于配置原则
9
9
  */
@@ -31,6 +31,8 @@ class Chan {
31
31
  this.loadKnex();
32
32
  //生命周期钩子:开始启动
33
33
  this.beforeStart();
34
+ //解决跨域
35
+ this.loadCors();
34
36
  //加载模块
35
37
  this.loadModules();
36
38
  //加载插件
@@ -112,6 +114,11 @@ class Chan {
112
114
  cb && cb();
113
115
  }
114
116
 
117
+ //解决跨域
118
+ loadCors(){
119
+ Chan.config?.cors?.origin && this.app.use(cors());
120
+ }
121
+
115
122
  // 加载插件
116
123
  loadPlugins() {
117
124
  this.loadModules('plugins');
@@ -28,6 +28,9 @@ let config = {
28
28
  password: "123456",
29
29
  database: "chanyue",
30
30
  charset: "utf8mb4",
31
+ },
32
+ cors:{
33
+ origin: '*'
31
34
  }
32
35
  }
33
36
 
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "chanjs",
3
- "version": "1.0.13",
3
+ "version": "1.0.14",
4
4
  "description": "Chanjs develops a lightweight MVC framework based on express pure JavaScript",
5
5
  "main": "core/chan.js",
6
- "module":"core/chan.js",
6
+ "module": "core/chan.js",
7
7
  "keywords": [
8
8
  "\"chanjs\"",
9
- "\"express mvc\"",
10
- "\"chancms\"",
11
- "\"nodejs\""
9
+ "\"express mvc\"",
10
+ "\"chancms\"",
11
+ "\"nodejs\""
12
12
  ],
13
13
  "author": "\"明空\"",
14
14
  "license": "ISC",
@@ -16,10 +16,11 @@
16
16
  "art-template": "^4.13.2",
17
17
  "body-parser": "^1.20.2",
18
18
  "cookie-parser": "^1.4.6",
19
+ "cors": "^2.8.5",
19
20
  "express": "^4.19.2",
20
21
  "express-art-template": "^1.0.1",
21
22
  "knex": "^3.1.0",
22
23
  "morgan": "^1.10.0",
23
24
  "mysql2": "^3.11.0"
24
25
  }
25
- }
26
+ }