chanjs 1.0.12 → 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
  //加载插件
@@ -100,7 +102,6 @@ class Chan {
100
102
  Chan.knex = knex;
101
103
  }
102
104
 
103
-
104
105
  //开始启动
105
106
  beforeStart(cb) {
106
107
  // 初始化一些配置
@@ -113,6 +114,11 @@ class Chan {
113
114
  cb && cb();
114
115
  }
115
116
 
117
+ //解决跨域
118
+ loadCors(){
119
+ Chan.config?.cors?.origin && this.app.use(cors());
120
+ }
121
+
116
122
  // 加载插件
117
123
  loadPlugins() {
118
124
  this.loadModules('plugins');
@@ -144,8 +150,6 @@ class Chan {
144
150
  };
145
151
  this.loadModule(modules,item);
146
152
  }
147
-
148
-
149
153
  //执行路由
150
154
  // this.app.use(this.router);
151
155
  }
@@ -170,7 +174,6 @@ class Chan {
170
174
  */
171
175
  loadServices(modules,moduleName) {
172
176
  const servicesDir = path.join(config.APP_PATH, modules, moduleName,"service");
173
-
174
177
  if (fs.existsSync(servicesDir)) {
175
178
  let services = fs
176
179
  .readdirSync(servicesDir)
@@ -227,15 +230,12 @@ class Chan {
227
230
  const baseRouterPath = path.join(config.APP_PATH, "router.js");
228
231
  if (fs.existsSync(baseRouterPath)) {
229
232
  const _router = require(baseRouterPath);
230
- console.log('_router-->',_router);
231
233
  _router(this.app, this.router);
232
234
  }
233
235
  } catch (error) {
234
236
  console.log(error);
235
237
  }
236
-
237
238
  }
238
-
239
239
 
240
240
  run() {
241
241
  const port = this.app.config.port || '81';
@@ -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.12",
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
- "express": "^4.18.2",
19
+ "cors": "^2.8.5",
20
+ "express": "^4.19.2",
20
21
  "express-art-template": "^1.0.1",
21
- "knex": "^3.0.1",
22
+ "knex": "^3.1.0",
22
23
  "morgan": "^1.10.0",
23
- "mysql2": "^3.6.2"
24
+ "mysql2": "^3.11.0"
24
25
  }
25
- }
26
+ }