cgserver 9.1.11 → 9.1.13
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.md +4 -0
- package/dist/lib/Framework/WebServer/Engine/Engine.js +8 -8
- package/dist/lib/Framework/WebServer/Engine/Response.js +5 -24
- package/dist/types/Framework/WebServer/Engine/Engine.d.ts +4 -4
- package/dist/types/Framework/WebServer/Engine/Response.d.ts +1 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,10 +109,10 @@ class Engine {
|
|
|
109
109
|
await this._callCtrAction(httpinfo.action_name, httpinfo.req, httpinfo.res);
|
|
110
110
|
}
|
|
111
111
|
_method_preactions = {
|
|
112
|
-
"
|
|
113
|
-
"
|
|
114
|
-
"
|
|
115
|
-
"
|
|
112
|
+
"post": "on",
|
|
113
|
+
"get": "show",
|
|
114
|
+
"options": "onoptions",
|
|
115
|
+
"head": "onhead"
|
|
116
116
|
};
|
|
117
117
|
/**
|
|
118
118
|
* 预处理http请求信息
|
|
@@ -125,13 +125,13 @@ class Engine {
|
|
|
125
125
|
let res = new Response_1.Response(_res, this._cfg);
|
|
126
126
|
//禁止访问
|
|
127
127
|
if (!this._is_running) {
|
|
128
|
-
res.
|
|
128
|
+
res.sendStatus(403);
|
|
129
129
|
return;
|
|
130
130
|
}
|
|
131
131
|
let method = req.method.toLocaleLowerCase();
|
|
132
132
|
let pre_action = this._method_preactions[method];
|
|
133
133
|
if (!pre_action) {
|
|
134
|
-
res.
|
|
134
|
+
res.sendStatus(500);
|
|
135
135
|
let info = req.getDebugInfo();
|
|
136
136
|
info["tip"] = "not support method:" + method;
|
|
137
137
|
Log_1.GLog.error(info);
|
|
@@ -139,7 +139,7 @@ class Engine {
|
|
|
139
139
|
}
|
|
140
140
|
let action_name = ControllerManager_1.GCtrMgr.getActionName(req.module, req.controller, pre_action + req.action);
|
|
141
141
|
if (!action_name) {
|
|
142
|
-
res.
|
|
142
|
+
res.sendStatus(500);
|
|
143
143
|
let info = req.getDebugInfo();
|
|
144
144
|
info["tip"] = "request has no action";
|
|
145
145
|
Log_1.GLog.error(info);
|
|
@@ -164,7 +164,7 @@ class Engine {
|
|
|
164
164
|
else {
|
|
165
165
|
ctr.initStatic(req, res, this);
|
|
166
166
|
}
|
|
167
|
-
ctr[action_name].call(ctr);
|
|
167
|
+
await ctr[action_name].call(ctr);
|
|
168
168
|
}
|
|
169
169
|
pause() {
|
|
170
170
|
if (!this._is_running) {
|
|
@@ -13,13 +13,10 @@ class Response {
|
|
|
13
13
|
return this._res;
|
|
14
14
|
}
|
|
15
15
|
constructor(res, cfg) {
|
|
16
|
+
this._create_time = Date.now();
|
|
16
17
|
this._cfg = cfg;
|
|
17
18
|
this._res = res;
|
|
18
19
|
this._cookie_prefix = this._cfg.cookie.prefix;
|
|
19
|
-
this._init();
|
|
20
|
-
}
|
|
21
|
-
_init() {
|
|
22
|
-
this._create_time = Date.now();
|
|
23
20
|
}
|
|
24
21
|
/**
|
|
25
22
|
*
|
|
@@ -50,25 +47,13 @@ class Response {
|
|
|
50
47
|
this.debugInfo(data);
|
|
51
48
|
return this._res.json(data);
|
|
52
49
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
renderJson500() {
|
|
57
|
-
this.debugInfo("500");
|
|
58
|
-
return this._res.status(500).json();
|
|
50
|
+
sendStatus(status) {
|
|
51
|
+
this.debugInfo(status);
|
|
52
|
+
this._res.sendStatus(status);
|
|
59
53
|
}
|
|
60
54
|
renderHtml(html) {
|
|
61
55
|
return this._res.send(html || "");
|
|
62
56
|
}
|
|
63
|
-
render404(html) {
|
|
64
|
-
return this._res.status(404).send(html || "没找到该页面");
|
|
65
|
-
}
|
|
66
|
-
render500(html) {
|
|
67
|
-
return this._res.status(500).send(html || "服务器内部错误500");
|
|
68
|
-
}
|
|
69
|
-
renderOptions(method, origin) {
|
|
70
|
-
this._res.sendStatus(204);
|
|
71
|
-
}
|
|
72
57
|
renderFile(fullPath) {
|
|
73
58
|
this._res.sendFile(fullPath);
|
|
74
59
|
}
|
|
@@ -80,7 +65,7 @@ class Response {
|
|
|
80
65
|
}
|
|
81
66
|
fs.stat(fullPath, (err, stats) => {
|
|
82
67
|
if (!stats || stats.isDirectory()) {
|
|
83
|
-
return this.
|
|
68
|
+
return this.sendStatus(404);
|
|
84
69
|
}
|
|
85
70
|
let size = stats.size;
|
|
86
71
|
var f = fs.createReadStream(fullPath);
|
|
@@ -92,14 +77,10 @@ class Response {
|
|
|
92
77
|
f.pipe(this._res);
|
|
93
78
|
});
|
|
94
79
|
}
|
|
95
|
-
render304() {
|
|
96
|
-
this._res.sendStatus(304);
|
|
97
|
-
}
|
|
98
80
|
debugInfo(data) {
|
|
99
81
|
if (!this._cfg.debug) {
|
|
100
82
|
return;
|
|
101
83
|
}
|
|
102
|
-
Log_1.GLog.info("dttime:" + (Date.now() - this._create_time).toLocaleString() + "ms");
|
|
103
84
|
Log_1.GLog.info(data);
|
|
104
85
|
}
|
|
105
86
|
}
|
|
@@ -19,10 +19,10 @@ export declare class Engine {
|
|
|
19
19
|
start(): void;
|
|
20
20
|
protected _onall(_req: Express.Request, _res: Express.Response): Promise<void>;
|
|
21
21
|
protected _method_preactions: {
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
22
|
+
post: string;
|
|
23
|
+
get: string;
|
|
24
|
+
options: string;
|
|
25
|
+
head: string;
|
|
26
26
|
};
|
|
27
27
|
/**
|
|
28
28
|
* 预处理http请求信息
|
|
@@ -7,7 +7,6 @@ export declare class Response {
|
|
|
7
7
|
protected _create_time: number;
|
|
8
8
|
get baseRes(): Express.Response<any, Record<string, any>>;
|
|
9
9
|
constructor(res: Express.Response, cfg: WebServerConfig);
|
|
10
|
-
protected _init(): void;
|
|
11
10
|
/**
|
|
12
11
|
*
|
|
13
12
|
* @param key
|
|
@@ -19,14 +18,9 @@ export declare class Response {
|
|
|
19
18
|
redirect(path: string): void;
|
|
20
19
|
render(data: any): Express.Response<any, Record<string, any>>;
|
|
21
20
|
renderJson(data: any): Express.Response<any, Record<string, any>>;
|
|
22
|
-
|
|
23
|
-
renderJson500(): Express.Response<any, Record<string, any>>;
|
|
21
|
+
sendStatus(status: number): void;
|
|
24
22
|
renderHtml(html: string): Express.Response<any, Record<string, any>>;
|
|
25
|
-
render404(html?: string): Express.Response<any, Record<string, any>>;
|
|
26
|
-
render500(html?: string): Express.Response<any, Record<string, any>>;
|
|
27
|
-
renderOptions(method: any, origin: any): void;
|
|
28
23
|
renderFile(fullPath: string): void;
|
|
29
24
|
downloadFile(fullPath: string): void;
|
|
30
|
-
render304(): void;
|
|
31
25
|
debugInfo(data: any): void;
|
|
32
26
|
}
|