@gieo/express 1.0.9 → 1.0.10

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/dist/index.js CHANGED
@@ -71,16 +71,16 @@ class ExpressPlus {
71
71
  return extendedReq.body;
72
72
  };
73
73
  extendedRes.status = function (code) {
74
- extendedRes.statusCode = code;
75
- return extendedRes;
76
- };
74
+ this.statusCode = code;
75
+ return this;
76
+ }.bind(this);
77
77
  extendedRes.json = function (data) {
78
- extendedRes.setHeader("Content-Type", "application/json");
79
- extendedRes.end(JSON.stringify(data));
80
- };
81
- // Thêm phương thức render cho EJS
78
+ this.setHeader("Content-Type", "application/json");
79
+ this.end(JSON.stringify(data));
80
+ }.bind(this);
81
+ // Bind render method with the correct context
82
82
  extendedRes.render = function (view, data = {}) {
83
- const filePath = path_1.default.join(this.viewsPath, `${view}.ejs`);
83
+ const filePath = path_1.default.join(this.viewsPath, `${view}.ejs`); // Sử dụng this.viewsPath từ instance
84
84
  if (!fs_1.default.existsSync(filePath)) {
85
85
  this.status(404).end(`View "${view}.ejs" not found in ${this.viewsPath}`);
86
86
  return;
@@ -88,7 +88,7 @@ class ExpressPlus {
88
88
  const html = ejs_1.default.render(fs_1.default.readFileSync(filePath, "utf-8"), data);
89
89
  this.setHeader("Content-Type", "text/html");
90
90
  this.end(html);
91
- };
91
+ }.bind(this); // Bind this để giữ context của ExpressPlus
92
92
  // 🔍 Tìm route phù hợp (hỗ trợ dynamic route)
93
93
  const route = this.routes[method].find((r) => {
94
94
  const routeParts = r.path.split("/").filter(Boolean);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gieo/express",
3
- "version": "1.0.9",
3
+ "version": "1.0.10",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "keywords": [],
package/src/index.ts CHANGED
@@ -43,7 +43,7 @@ class ExpressPlus {
43
43
  next: () => void
44
44
  ) => void)[] = [];
45
45
 
46
- // Định nghĩa thư mục chứa views với giá trị mặc định và cho phép tùy chỉnh
46
+ // Lưu viewsPath như một thuộc tính của instance
47
47
  private viewsPath: string;
48
48
 
49
49
  constructor(options: { viewsPath?: string } = {}) {
@@ -119,18 +119,18 @@ class ExpressPlus {
119
119
  };
120
120
 
121
121
  extendedRes.status = function (code: number) {
122
- extendedRes.statusCode = code;
123
- return extendedRes;
124
- };
122
+ this.statusCode = code;
123
+ return this;
124
+ }.bind(this);
125
125
 
126
126
  extendedRes.json = function (data: any) {
127
- extendedRes.setHeader("Content-Type", "application/json");
128
- extendedRes.end(JSON.stringify(data));
129
- };
127
+ this.setHeader("Content-Type", "application/json");
128
+ this.end(JSON.stringify(data));
129
+ }.bind(this);
130
130
 
131
- // Thêm phương thức render cho EJS
131
+ // Bind render method with the correct context
132
132
  extendedRes.render = function (view: string, data: any = {}) {
133
- const filePath = path.join(this.viewsPath, `${view}.ejs`);
133
+ const filePath = path.join(this.viewsPath, `${view}.ejs`); // Sử dụng this.viewsPath từ instance
134
134
  if (!fs.existsSync(filePath)) {
135
135
  this.status(404).end(
136
136
  `View "${view}.ejs" not found in ${this.viewsPath}`
@@ -140,7 +140,7 @@ class ExpressPlus {
140
140
  const html = ejs.render(fs.readFileSync(filePath, "utf-8"), data);
141
141
  this.setHeader("Content-Type", "text/html");
142
142
  this.end(html);
143
- };
143
+ }.bind(this); // Bind this để giữ context của ExpressPlus
144
144
 
145
145
  // 🔍 Tìm route phù hợp (hỗ trợ dynamic route)
146
146
  const route = this.routes[method].find((r) => {