azurajs 2.1.2 → 2.2.0
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 +244 -7
- package/dist/LoggingMiddleware-BQKJUBqT.d.ts +6 -0
- package/dist/LoggingMiddleware-CYNvypha.d.cts +6 -0
- package/dist/Server-Ba-EFdi2.d.ts +53 -0
- package/dist/Server-CY3k1FIL.d.cts +53 -0
- package/dist/common.type-BoV71o_C.d.ts +11 -0
- package/dist/common.type-Ct06XeYQ.d.cts +11 -0
- package/dist/config.cjs +89 -0
- package/dist/config.cjs.map +1 -0
- package/dist/config.d.cts +51 -0
- package/dist/config.d.ts +51 -0
- package/dist/config.js +83 -0
- package/dist/config.js.map +1 -0
- package/dist/cookies.cjs +32 -0
- package/dist/cookies.cjs.map +1 -0
- package/dist/cookies.d.cts +8 -0
- package/dist/cookies.d.ts +8 -0
- package/dist/cookies.js +29 -0
- package/dist/cookies.js.map +1 -0
- package/dist/cors.cjs +29 -0
- package/dist/cors.cjs.map +1 -0
- package/dist/cors.d.cts +14 -0
- package/dist/cors.d.ts +14 -0
- package/dist/cors.js +27 -0
- package/dist/cors.js.map +1 -0
- package/dist/decorators.cjs +141 -0
- package/dist/decorators.cjs.map +1 -0
- package/dist/decorators.d.cts +29 -0
- package/dist/decorators.d.ts +29 -0
- package/dist/decorators.js +122 -0
- package/dist/decorators.js.map +1 -0
- package/dist/http-error.cjs +14 -0
- package/dist/http-error.cjs.map +1 -0
- package/dist/http-error.d.cts +7 -0
- package/dist/http-error.d.ts +7 -0
- package/dist/http-error.js +12 -0
- package/dist/http-error.js.map +1 -0
- package/dist/index.cjs +910 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +899 -0
- package/dist/index.js.map +1 -0
- package/dist/infra.cjs +811 -0
- package/dist/infra.cjs.map +1 -0
- package/dist/infra.d.cts +8 -0
- package/dist/infra.d.ts +8 -0
- package/dist/infra.js +800 -0
- package/dist/infra.js.map +1 -0
- package/dist/logger.cjs +26 -0
- package/dist/logger.cjs.map +1 -0
- package/dist/logger.d.cts +8 -0
- package/dist/logger.d.ts +8 -0
- package/dist/logger.js +24 -0
- package/dist/logger.js.map +1 -0
- package/dist/middleware.cjs +117 -0
- package/dist/middleware.cjs.map +1 -0
- package/dist/middleware.d.cts +10 -0
- package/dist/middleware.d.ts +10 -0
- package/dist/middleware.js +114 -0
- package/dist/middleware.js.map +1 -0
- package/dist/plugins.cjs +52 -0
- package/dist/plugins.cjs.map +1 -0
- package/dist/plugins.d.cts +6 -0
- package/dist/plugins.d.ts +6 -0
- package/dist/plugins.js +49 -0
- package/dist/plugins.js.map +1 -0
- package/dist/rate-limit.cjs +27 -0
- package/dist/rate-limit.cjs.map +1 -0
- package/dist/rate-limit.d.cts +8 -0
- package/dist/rate-limit.d.ts +8 -0
- package/dist/rate-limit.js +25 -0
- package/dist/rate-limit.js.map +1 -0
- package/dist/request.type-CJ-EGGcM.d.cts +22 -0
- package/dist/request.type-CJ-EGGcM.d.ts +22 -0
- package/dist/response.type-d6e6eU9D.d.cts +33 -0
- package/dist/response.type-d6e6eU9D.d.ts +33 -0
- package/dist/router.cjs +111 -0
- package/dist/router.cjs.map +1 -0
- package/dist/router.d.cts +27 -0
- package/dist/router.d.ts +27 -0
- package/dist/router.js +109 -0
- package/dist/router.js.map +1 -0
- package/dist/routes.type-VPROfhnL.d.cts +14 -0
- package/dist/routes.type-VPROfhnL.d.ts +14 -0
- package/dist/types.cjs +4 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.cts +6 -0
- package/dist/types.d.ts +6 -0
- package/dist/types.js +3 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.cjs +149 -0
- package/dist/utils.cjs.map +1 -0
- package/dist/utils.d.cts +10 -0
- package/dist/utils.d.ts +10 -0
- package/dist/utils.js +141 -0
- package/dist/utils.js.map +1 -0
- package/dist/validations.type-D4ZhF5g6.d.cts +6 -0
- package/dist/validations.type-D4ZhF5g6.d.ts +6 -0
- package/dist/validators.cjs +69 -0
- package/dist/validators.cjs.map +1 -0
- package/dist/validators.d.cts +11 -0
- package/dist/validators.d.ts +11 -0
- package/dist/validators.js +65 -0
- package/dist/validators.js.map +1 -0
- package/package.json +85 -66
- package/src/index.ts +1 -3
- package/src/infra/Router.ts +53 -3
- package/src/infra/Server.ts +37 -10
- package/src/infra/index.ts +1 -1
- package/src/shared/config/ConfigModule.ts +1 -0
package/package.json
CHANGED
|
@@ -1,145 +1,163 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "azurajs",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.2.0",
|
|
4
4
|
"description": "Modern TypeScript-first web framework with decorator-based routing, zero dependencies, and built for performance",
|
|
5
|
-
"main": "./
|
|
6
|
-
"module": "./
|
|
7
|
-
"types": "./
|
|
5
|
+
"main": "./dist/index.cjs",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"exports": {
|
|
10
10
|
".": {
|
|
11
|
-
"types": "./
|
|
12
|
-
"import": "./
|
|
13
|
-
"
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs",
|
|
14
|
+
"default": "./dist/index.js"
|
|
14
15
|
},
|
|
15
16
|
"./decorators": {
|
|
16
|
-
"types": "./
|
|
17
|
-
"import": "./
|
|
18
|
-
"
|
|
17
|
+
"types": "./dist/decorators.d.ts",
|
|
18
|
+
"import": "./dist/decorators.js",
|
|
19
|
+
"require": "./dist/decorators.cjs",
|
|
20
|
+
"default": "./dist/decorators.js"
|
|
19
21
|
},
|
|
20
22
|
"./middleware": {
|
|
21
|
-
"types": "./
|
|
22
|
-
"import": "./
|
|
23
|
-
"
|
|
23
|
+
"types": "./dist/middleware.d.ts",
|
|
24
|
+
"import": "./dist/middleware.js",
|
|
25
|
+
"require": "./dist/middleware.cjs",
|
|
26
|
+
"default": "./dist/middleware.js"
|
|
24
27
|
},
|
|
25
28
|
"./types": {
|
|
26
|
-
"types": "./
|
|
27
|
-
"import": "./
|
|
28
|
-
"
|
|
29
|
+
"types": "./dist/types.d.ts",
|
|
30
|
+
"import": "./dist/types.js",
|
|
31
|
+
"require": "./dist/types.cjs",
|
|
32
|
+
"default": "./dist/types.js"
|
|
29
33
|
},
|
|
30
34
|
"./infra": {
|
|
31
|
-
"types": "./
|
|
32
|
-
"import": "./
|
|
33
|
-
"
|
|
35
|
+
"types": "./dist/infra.d.ts",
|
|
36
|
+
"import": "./dist/infra.js",
|
|
37
|
+
"require": "./dist/infra.cjs",
|
|
38
|
+
"default": "./dist/infra.js"
|
|
34
39
|
},
|
|
35
40
|
"./router": {
|
|
36
|
-
"types": "./
|
|
37
|
-
"import": "./
|
|
38
|
-
"
|
|
41
|
+
"types": "./dist/router.d.ts",
|
|
42
|
+
"import": "./dist/router.js",
|
|
43
|
+
"require": "./dist/router.cjs",
|
|
44
|
+
"default": "./dist/router.js"
|
|
39
45
|
},
|
|
40
46
|
"./config": {
|
|
41
|
-
"types": "./
|
|
42
|
-
"import": "./
|
|
43
|
-
"
|
|
47
|
+
"types": "./dist/config.d.ts",
|
|
48
|
+
"import": "./dist/config.js",
|
|
49
|
+
"require": "./dist/config.cjs",
|
|
50
|
+
"default": "./dist/config.js"
|
|
44
51
|
},
|
|
45
52
|
"./plugins": {
|
|
46
|
-
"types": "./
|
|
47
|
-
"import": "./
|
|
48
|
-
"
|
|
53
|
+
"types": "./dist/plugins.d.ts",
|
|
54
|
+
"import": "./dist/plugins.js",
|
|
55
|
+
"require": "./dist/plugins.cjs",
|
|
56
|
+
"default": "./dist/plugins.js"
|
|
49
57
|
},
|
|
50
58
|
"./cors": {
|
|
51
|
-
"types": "./
|
|
52
|
-
"import": "./
|
|
53
|
-
"
|
|
59
|
+
"types": "./dist/cors.d.ts",
|
|
60
|
+
"import": "./dist/cors.js",
|
|
61
|
+
"require": "./dist/cors.cjs",
|
|
62
|
+
"default": "./dist/cors.js"
|
|
54
63
|
},
|
|
55
64
|
"./rate-limit": {
|
|
56
|
-
"types": "./
|
|
57
|
-
"import": "./
|
|
58
|
-
"
|
|
65
|
+
"types": "./dist/rate-limit.d.ts",
|
|
66
|
+
"import": "./dist/rate-limit.js",
|
|
67
|
+
"require": "./dist/rate-limit.cjs",
|
|
68
|
+
"default": "./dist/rate-limit.js"
|
|
59
69
|
},
|
|
60
70
|
"./utils": {
|
|
61
|
-
"types": "./
|
|
62
|
-
"import": "./
|
|
63
|
-
"
|
|
71
|
+
"types": "./dist/utils.d.ts",
|
|
72
|
+
"import": "./dist/utils.js",
|
|
73
|
+
"require": "./dist/utils.cjs",
|
|
74
|
+
"default": "./dist/utils.js"
|
|
64
75
|
},
|
|
65
76
|
"./cookies": {
|
|
66
|
-
"types": "./
|
|
67
|
-
"import": "./
|
|
68
|
-
"
|
|
77
|
+
"types": "./dist/cookies.d.ts",
|
|
78
|
+
"import": "./dist/cookies.js",
|
|
79
|
+
"require": "./dist/cookies.cjs",
|
|
80
|
+
"default": "./dist/cookies.js"
|
|
69
81
|
},
|
|
70
82
|
"./validators": {
|
|
71
|
-
"types": "./
|
|
72
|
-
"import": "./
|
|
73
|
-
"
|
|
83
|
+
"types": "./dist/validators.d.ts",
|
|
84
|
+
"import": "./dist/validators.js",
|
|
85
|
+
"require": "./dist/validators.cjs",
|
|
86
|
+
"default": "./dist/validators.js"
|
|
74
87
|
},
|
|
75
88
|
"./logger": {
|
|
76
|
-
"types": "./
|
|
77
|
-
"import": "./
|
|
78
|
-
"
|
|
89
|
+
"types": "./dist/logger.d.ts",
|
|
90
|
+
"import": "./dist/logger.js",
|
|
91
|
+
"require": "./dist/logger.cjs",
|
|
92
|
+
"default": "./dist/logger.js"
|
|
79
93
|
},
|
|
80
94
|
"./http-error": {
|
|
81
|
-
"types": "./
|
|
82
|
-
"import": "./
|
|
83
|
-
"
|
|
95
|
+
"types": "./dist/http-error.d.ts",
|
|
96
|
+
"import": "./dist/http-error.js",
|
|
97
|
+
"require": "./dist/http-error.cjs",
|
|
98
|
+
"default": "./dist/http-error.js"
|
|
84
99
|
},
|
|
85
100
|
"./package.json": "./package.json"
|
|
86
101
|
},
|
|
87
102
|
"typesVersions": {
|
|
88
103
|
"*": {
|
|
89
104
|
"*": [
|
|
90
|
-
"./
|
|
105
|
+
"./dist/*"
|
|
91
106
|
],
|
|
92
107
|
"decorators": [
|
|
93
|
-
"./
|
|
108
|
+
"./dist/decorators.d.ts"
|
|
94
109
|
],
|
|
95
110
|
"middleware": [
|
|
96
|
-
"./
|
|
111
|
+
"./dist/middleware.d.ts"
|
|
97
112
|
],
|
|
98
113
|
"types": [
|
|
99
|
-
"./
|
|
114
|
+
"./dist/types.d.ts"
|
|
100
115
|
],
|
|
101
116
|
"infra": [
|
|
102
|
-
"./
|
|
117
|
+
"./dist/infra.d.ts"
|
|
103
118
|
],
|
|
104
119
|
"router": [
|
|
105
|
-
"./
|
|
120
|
+
"./dist/router.d.ts"
|
|
106
121
|
],
|
|
107
122
|
"config": [
|
|
108
|
-
"./
|
|
123
|
+
"./dist/config.d.ts"
|
|
109
124
|
],
|
|
110
125
|
"plugins": [
|
|
111
|
-
"./
|
|
126
|
+
"./dist/plugins.d.ts"
|
|
112
127
|
],
|
|
113
128
|
"cors": [
|
|
114
|
-
"./
|
|
129
|
+
"./dist/cors.d.ts"
|
|
115
130
|
],
|
|
116
131
|
"rate-limit": [
|
|
117
|
-
"./
|
|
132
|
+
"./dist/rate-limit.d.ts"
|
|
118
133
|
],
|
|
119
134
|
"utils": [
|
|
120
|
-
"./
|
|
135
|
+
"./dist/utils.d.ts"
|
|
121
136
|
],
|
|
122
137
|
"cookies": [
|
|
123
|
-
"./
|
|
138
|
+
"./dist/cookies.d.ts"
|
|
124
139
|
],
|
|
125
140
|
"validators": [
|
|
126
|
-
"./
|
|
141
|
+
"./dist/validators.d.ts"
|
|
127
142
|
],
|
|
128
143
|
"logger": [
|
|
129
|
-
"./
|
|
144
|
+
"./dist/logger.d.ts"
|
|
130
145
|
],
|
|
131
146
|
"http-error": [
|
|
132
|
-
"./
|
|
147
|
+
"./dist/http-error.d.ts"
|
|
133
148
|
]
|
|
134
149
|
}
|
|
135
150
|
},
|
|
136
151
|
"files": [
|
|
152
|
+
"dist",
|
|
137
153
|
"src",
|
|
138
154
|
"README.md",
|
|
139
155
|
"LICENSE"
|
|
140
156
|
],
|
|
141
157
|
"scripts": {
|
|
142
|
-
"
|
|
158
|
+
"build": "tsup",
|
|
159
|
+
"build:watch": "tsup --watch",
|
|
160
|
+
"prepublishOnly": "bun run build",
|
|
143
161
|
"test": "bun test"
|
|
144
162
|
},
|
|
145
163
|
"keywords": [
|
|
@@ -174,7 +192,8 @@
|
|
|
174
192
|
"bun": ">=1.0.0"
|
|
175
193
|
},
|
|
176
194
|
"devDependencies": {
|
|
177
|
-
"@types/bun": "latest"
|
|
195
|
+
"@types/bun": "latest",
|
|
196
|
+
"tsup": "^8.5.1"
|
|
178
197
|
},
|
|
179
198
|
"peerDependencies": {
|
|
180
199
|
"typescript": "^5.0.0"
|
package/src/index.ts
CHANGED
package/src/infra/Router.ts
CHANGED
|
@@ -8,6 +8,11 @@ interface MatchResult {
|
|
|
8
8
|
|
|
9
9
|
export class Router {
|
|
10
10
|
private root = new Node();
|
|
11
|
+
private debug: boolean;
|
|
12
|
+
|
|
13
|
+
constructor(debug = false) {
|
|
14
|
+
this.debug = debug;
|
|
15
|
+
}
|
|
11
16
|
|
|
12
17
|
add(method: string, path: string, ...handlers: Handler[]) {
|
|
13
18
|
const segments = path.split("/").filter(Boolean);
|
|
@@ -32,14 +37,22 @@ export class Router {
|
|
|
32
37
|
}
|
|
33
38
|
|
|
34
39
|
find(method: string, path: string): MatchResult {
|
|
35
|
-
const
|
|
40
|
+
const cleanPath = path.split("?")[0];
|
|
41
|
+
const segments = cleanPath?.split("/").filter(Boolean) ?? [];
|
|
36
42
|
let node = this.root;
|
|
37
43
|
const params: Record<string, string> = {};
|
|
38
|
-
|
|
44
|
+
|
|
45
|
+
if (this.debug && segments?.length === 0 && node.handlers.size === 0) {
|
|
46
|
+
console.error("[Router:DEBUG] Root node has no handlers");
|
|
47
|
+
console.error("[Router:DEBUG] Available methods at root:", Array.from(node.handlers.keys()));
|
|
48
|
+
}
|
|
49
|
+
|
|
39
50
|
for (let i = 0; i < segments.length; i++) {
|
|
40
51
|
const seg = segments[i];
|
|
52
|
+
if (!seg) continue;
|
|
53
|
+
|
|
41
54
|
let child = node.children.get(seg);
|
|
42
|
-
|
|
55
|
+
|
|
43
56
|
if (child) {
|
|
44
57
|
node = child;
|
|
45
58
|
} else {
|
|
@@ -50,6 +63,12 @@ export class Router {
|
|
|
50
63
|
params[node.paramName] = seg;
|
|
51
64
|
}
|
|
52
65
|
} else {
|
|
66
|
+
// Debug melhorado - só mostra se debug estiver ativo
|
|
67
|
+
if (this.debug) {
|
|
68
|
+
console.error(`[Router:DEBUG] Route not found for ${method} ${cleanPath}`);
|
|
69
|
+
console.error(`[Router:DEBUG] Failed at segment: "${seg}"`);
|
|
70
|
+
console.error(`[Router:DEBUG] Available children:`, Array.from(node.children.keys()));
|
|
71
|
+
}
|
|
53
72
|
throw new HttpError(404, "Route not found");
|
|
54
73
|
}
|
|
55
74
|
}
|
|
@@ -57,8 +76,39 @@ export class Router {
|
|
|
57
76
|
|
|
58
77
|
const handlers = node.handlers.get(method.toUpperCase()) as Handler[];
|
|
59
78
|
if (!handlers) {
|
|
79
|
+
if (this.debug) {
|
|
80
|
+
console.error(
|
|
81
|
+
`[Router:DEBUG] No handlers for method ${method.toUpperCase()} at path ${cleanPath}`
|
|
82
|
+
);
|
|
83
|
+
console.error(
|
|
84
|
+
`[Router:DEBUG] Available methods at this path:`,
|
|
85
|
+
Array.from(node.handlers.keys())
|
|
86
|
+
);
|
|
87
|
+
console.error(`[Router:DEBUG] Segments matched:`, segments);
|
|
88
|
+
}
|
|
60
89
|
throw new HttpError(404, "Route not found");
|
|
61
90
|
}
|
|
62
91
|
return { handlers, params };
|
|
63
92
|
}
|
|
93
|
+
|
|
94
|
+
public listRoutes(): Array<{ method: string; path: string }> {
|
|
95
|
+
const routes: Array<{ method: string; path: string }> = [];
|
|
96
|
+
|
|
97
|
+
const traverse = (node: Node, path: string) => {
|
|
98
|
+
if (node.handlers.size > 0) {
|
|
99
|
+
for (const method of node.handlers.keys()) {
|
|
100
|
+
routes.push({ method, path: path || "/" });
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
for (const [segment, child] of node.children) {
|
|
105
|
+
const newPath =
|
|
106
|
+
path + "/" + (segment === ":" && child.paramName ? `:${child.paramName}` : segment);
|
|
107
|
+
traverse(child, newPath);
|
|
108
|
+
}
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
traverse(this.root, "");
|
|
112
|
+
return routes;
|
|
113
|
+
}
|
|
64
114
|
}
|
package/src/infra/Server.ts
CHANGED
|
@@ -28,7 +28,7 @@ export class AzuraClient {
|
|
|
28
28
|
private port: number = 3000;
|
|
29
29
|
private initPromise: Promise<void>;
|
|
30
30
|
|
|
31
|
-
public router
|
|
31
|
+
public router: Router;
|
|
32
32
|
private middlewares: RequestHandler[] = [];
|
|
33
33
|
|
|
34
34
|
constructor() {
|
|
@@ -41,7 +41,22 @@ export class AzuraClient {
|
|
|
41
41
|
process.exit(1);
|
|
42
42
|
}
|
|
43
43
|
this.opts = config.getAll();
|
|
44
|
+
this.router = new Router(this.opts.debug || false);
|
|
44
45
|
this.initPromise = this.init();
|
|
46
|
+
this.setupDefaultRoutes();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Configura rotas padrão para evitar erros 404 comuns
|
|
51
|
+
*/
|
|
52
|
+
private setupDefaultRoutes() {
|
|
53
|
+
this.router.add(
|
|
54
|
+
"GET",
|
|
55
|
+
"/favicon.ico",
|
|
56
|
+
adaptRequestHandler((ctx: any) => {
|
|
57
|
+
ctx.res.status(204).send();
|
|
58
|
+
}) as any
|
|
59
|
+
);
|
|
45
60
|
}
|
|
46
61
|
|
|
47
62
|
public getConfig() {
|
|
@@ -92,6 +107,10 @@ export class AzuraClient {
|
|
|
92
107
|
public delete = (p: string, ...h: RequestHandler[]) => this.addRoute("DELETE", p, ...h);
|
|
93
108
|
public patch = (p: string, ...h: RequestHandler[]) => this.addRoute("PATCH", p, ...h);
|
|
94
109
|
|
|
110
|
+
public getRoutes() {
|
|
111
|
+
return this.router.listRoutes();
|
|
112
|
+
}
|
|
113
|
+
|
|
95
114
|
public async listen(port = this.port) {
|
|
96
115
|
await this.initPromise;
|
|
97
116
|
|
|
@@ -113,6 +132,14 @@ export class AzuraClient {
|
|
|
113
132
|
this.server.listen(port, () => {
|
|
114
133
|
logger("info", `[${who}] listening on http://localhost:${port}`);
|
|
115
134
|
if (this.opts.server?.ipHost) getIP(port);
|
|
135
|
+
|
|
136
|
+
const routes = this.getRoutes();
|
|
137
|
+
if (routes.length > 0) {
|
|
138
|
+
logger("info", `\n📋 Registered routes (${routes.length}):`);
|
|
139
|
+
routes.forEach((r) => {
|
|
140
|
+
logger("info", ` ${r.method.padEnd(7)} ${r.path}`);
|
|
141
|
+
});
|
|
142
|
+
}
|
|
116
143
|
});
|
|
117
144
|
|
|
118
145
|
return this.server;
|
|
@@ -124,13 +151,13 @@ export class AzuraClient {
|
|
|
124
151
|
* ```typescript
|
|
125
152
|
* const app = new AzuraClient();
|
|
126
153
|
* app.get('/', (req, res) => res.text('Hello World!'));
|
|
127
|
-
*
|
|
154
|
+
*
|
|
128
155
|
* // Use with Bun
|
|
129
156
|
* Bun.serve({
|
|
130
157
|
* port: 3000,
|
|
131
158
|
* fetch: app.fetch.bind(app),
|
|
132
159
|
* });
|
|
133
|
-
*
|
|
160
|
+
*
|
|
134
161
|
* // Use with Deno
|
|
135
162
|
* Deno.serve({ port: 3000 }, app.fetch.bind(app));
|
|
136
163
|
* ```
|
|
@@ -140,13 +167,13 @@ export class AzuraClient {
|
|
|
140
167
|
|
|
141
168
|
const url = new URL(request.url);
|
|
142
169
|
const urlPath = url.pathname;
|
|
143
|
-
|
|
170
|
+
|
|
144
171
|
const safeQuery: Record<string, string> = {};
|
|
145
172
|
if (url.search) {
|
|
146
173
|
const rawQuery = parseQS(url.search.slice(1));
|
|
147
174
|
for (const k in rawQuery) {
|
|
148
175
|
const v = rawQuery[k];
|
|
149
|
-
safeQuery[k] = Array.isArray(v) ? v[0] || "" : v as string;
|
|
176
|
+
safeQuery[k] = Array.isArray(v) ? v[0] || "" : (v as string);
|
|
150
177
|
}
|
|
151
178
|
}
|
|
152
179
|
|
|
@@ -177,12 +204,12 @@ export class AzuraClient {
|
|
|
177
204
|
}
|
|
178
205
|
|
|
179
206
|
const protocol = url.protocol.slice(0, -1) as "http" | "https";
|
|
180
|
-
|
|
207
|
+
|
|
181
208
|
const headersObj: Record<string, string | string[]> = {};
|
|
182
209
|
request.headers.forEach((value, key) => {
|
|
183
210
|
headersObj[key] = value;
|
|
184
211
|
});
|
|
185
|
-
|
|
212
|
+
|
|
186
213
|
const rawReq: Partial<RequestServer> = {
|
|
187
214
|
method: request.method,
|
|
188
215
|
url: url.pathname + url.search,
|
|
@@ -288,12 +315,12 @@ export class AzuraClient {
|
|
|
288
315
|
try {
|
|
289
316
|
const { handlers, params } = this.router.find(request.method, urlPath || "/");
|
|
290
317
|
rawReq.params = params || {};
|
|
291
|
-
|
|
318
|
+
|
|
292
319
|
const chain = [
|
|
293
320
|
...this.middlewares.map(adaptRequestHandler),
|
|
294
321
|
...handlers.map(adaptRequestHandler),
|
|
295
322
|
];
|
|
296
|
-
|
|
323
|
+
|
|
297
324
|
let idx = 0;
|
|
298
325
|
const next = async (err?: any) => {
|
|
299
326
|
if (err) return errorHandler(err);
|
|
@@ -311,7 +338,7 @@ export class AzuraClient {
|
|
|
311
338
|
return errorHandler(e);
|
|
312
339
|
}
|
|
313
340
|
};
|
|
314
|
-
|
|
341
|
+
|
|
315
342
|
await next();
|
|
316
343
|
} catch (err) {
|
|
317
344
|
errorHandler(err);
|
package/src/infra/index.ts
CHANGED