jj.js 1.0.0-rc.1 → 1.0.0-rc.2
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/lib/config.js +1 -1
- package/lib/loader.js +1 -1
- package/lib/response.js +1 -1
- package/lib/router.js +3 -3
- package/lib/types.js +1 -1
- package/lib/utils/escape-html.js +15 -0
- package/lib/utils/is-class.js +12 -0
- package/package.json +8 -10
package/lib/config.js
CHANGED
|
@@ -20,7 +20,7 @@ const view = {
|
|
|
20
20
|
view_folder: 'view', // 模板目录名
|
|
21
21
|
view_depr: '/', // 模版文件名分割符,'/'代表二级目录
|
|
22
22
|
view_ext: '.htm', // 模版后缀
|
|
23
|
-
view_engine: 'art-template', // 默认模版引擎,字符串或引擎类
|
|
23
|
+
view_engine: '@yafoo/art-template', // 默认模版引擎,字符串或引擎类
|
|
24
24
|
view_filter: {}, // 模版函数
|
|
25
25
|
}
|
|
26
26
|
|
package/lib/loader.js
CHANGED
package/lib/response.js
CHANGED
|
@@ -101,7 +101,7 @@ class Response extends Context
|
|
|
101
101
|
* @param {Error} err
|
|
102
102
|
*/
|
|
103
103
|
exception(err) {
|
|
104
|
-
const escapeHtml = require('escape-html');
|
|
104
|
+
const escapeHtml = require('./utils/escape-html');
|
|
105
105
|
const tplData = parseError(err);
|
|
106
106
|
tplData.msg = escapeHtml(tplData.msg);
|
|
107
107
|
// @ts-ignore
|
package/lib/router.js
CHANGED
|
@@ -50,15 +50,15 @@ if (cfg_routes) {
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
// 注册系统路由
|
|
53
|
-
router.all('/
|
|
53
|
+
router.all('/{*path}', async (ctx, next) => {
|
|
54
54
|
if(ctx._routeMatched) return await next();
|
|
55
55
|
|
|
56
|
-
let param = ctx.params
|
|
56
|
+
let param = ctx.params.path ?? '';
|
|
57
57
|
const dotIndex = param.indexOf('.');
|
|
58
58
|
if(~dotIndex) param = param.slice(0, dotIndex);
|
|
59
59
|
try {
|
|
60
60
|
resolveRoute(param, ctx, cfg_app.controller_folder);
|
|
61
|
-
delete ctx.params
|
|
61
|
+
delete ctx.params.path;
|
|
62
62
|
} catch (error) {
|
|
63
63
|
if(cfg_app.app_debug) throw error;
|
|
64
64
|
return;
|
package/lib/types.js
CHANGED
|
@@ -258,7 +258,7 @@ class TypesGenerator {
|
|
|
258
258
|
* @returns {Promise<Object<string, NodeInfo>>}
|
|
259
259
|
*/
|
|
260
260
|
async getNodeList(dir, ignore = []) {
|
|
261
|
-
const isClass = require('is-class');
|
|
261
|
+
const isClass = require('./utils/is-class');
|
|
262
262
|
let files;
|
|
263
263
|
try {
|
|
264
264
|
files = await fsPromises.readdir(dir, {withFileTypes: true});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 转义 HTML 特殊字符,防止 XSS 攻击
|
|
3
|
+
* @param {string} str - 需要转义的字符串
|
|
4
|
+
* @returns {string} 转义后的字符串
|
|
5
|
+
*/
|
|
6
|
+
function escapeHtml(str) {
|
|
7
|
+
return String(str)
|
|
8
|
+
.replace(/&/g, '&')
|
|
9
|
+
.replace(/</g, '<')
|
|
10
|
+
.replace(/>/g, '>')
|
|
11
|
+
.replace(/"/g, '"')
|
|
12
|
+
.replace(/'/g, ''');
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
module.exports = escapeHtml;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 判断一个值是否是 ES6 class
|
|
3
|
+
* @param {*} fn - 需要判断的值
|
|
4
|
+
* @returns {boolean} 是否是 class
|
|
5
|
+
*/
|
|
6
|
+
function isClass(fn) {
|
|
7
|
+
if (typeof fn !== 'function') return false;
|
|
8
|
+
const str = Function.prototype.toString.call(fn);
|
|
9
|
+
return /^class[\s{]/.test(str);
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
module.exports = isClass;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "jj.js",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.2",
|
|
4
4
|
"description": "A super simple lightweight NodeJS MVC framework(一个超级简单轻量的NodeJS MVC框架)",
|
|
5
5
|
"main": "jj.js",
|
|
6
6
|
"scripts": {
|
|
@@ -23,19 +23,17 @@
|
|
|
23
23
|
},
|
|
24
24
|
"homepage": "https://github.com/yafoo/jj.js#readme",
|
|
25
25
|
"dependencies": {
|
|
26
|
-
"@koa/router": "^
|
|
27
|
-
"art-template": "^
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"koa": "^2.16.0",
|
|
31
|
-
"koa-body": "^6.0.1",
|
|
26
|
+
"@koa/router": "^15.7.0",
|
|
27
|
+
"@yafoo/art-template": "^5.1.0",
|
|
28
|
+
"koa": "^3.2.1",
|
|
29
|
+
"koa-body": "^8.0.0",
|
|
32
30
|
"koa-static": "^5.0.0",
|
|
33
|
-
"mongodb": "^
|
|
31
|
+
"mongodb": "^7.5.0",
|
|
34
32
|
"mysql": "^2.18.1",
|
|
35
|
-
"sqlite3": "^
|
|
33
|
+
"sqlite3": "^6.0.1"
|
|
36
34
|
},
|
|
37
35
|
"engines": {
|
|
38
|
-
"node": ">=
|
|
36
|
+
"node": ">= 20.19.0"
|
|
39
37
|
},
|
|
40
38
|
"devDependencies": {
|
|
41
39
|
"supertest": "^7.2.2"
|