@athenna/http 4.8.0 → 4.10.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/package.json +220 -233
- package/src/commands/RouteListCommand.d.ts +4 -0
- package/src/commands/RouteListCommand.js +9 -2
- package/src/context/Request.js +1 -1
- package/src/index.d.ts +1 -1
- package/src/index.js +1 -1
- package/src/kernels/HttpKernel.d.ts +4 -4
- package/src/kernels/HttpKernel.js +14 -14
- package/src/router/Route.js +5 -2
- package/src/server/ServerImpl.d.ts +4 -4
- package/src/server/ServerImpl.js +2 -1
- package/src/types/index.d.ts +1 -0
- package/src/types/index.js +1 -0
- package/src/types/swagger/SwaggerDocument.d.ts +10 -0
- package/src/types/swagger/SwaggerDocument.js +9 -0
- package/templates/controller.edge +0 -24
- package/templates/interceptor.edge +0 -9
- package/templates/middleware.edge +0 -7
- package/templates/terminator.edge +0 -7
package/package.json
CHANGED
|
@@ -1,243 +1,230 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
"name": "@athenna/http",
|
|
3
|
+
"version": "4.10.0",
|
|
4
|
+
"description": "The Athenna Http server. Built on top of fastify.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "João Lenon <lenon@athenna.io>",
|
|
7
|
+
"bugs": "https://github.com/AthennaIO/Http/issues",
|
|
8
|
+
"repository": "https://github.com/AthennaIO/Http.git",
|
|
9
|
+
"homepage": "https://github.com/AthennaIO/Http#readme",
|
|
10
|
+
"keywords": [
|
|
11
|
+
"fastify",
|
|
12
|
+
"router",
|
|
13
|
+
"cors",
|
|
14
|
+
"ctx",
|
|
15
|
+
"helmet",
|
|
16
|
+
"swagger",
|
|
17
|
+
"exception-handling",
|
|
18
|
+
"rate-limiting",
|
|
19
|
+
"middlewares",
|
|
20
|
+
"terminators",
|
|
21
|
+
"interceptors",
|
|
22
|
+
"http-server",
|
|
23
|
+
"athenna",
|
|
24
|
+
"esm"
|
|
25
|
+
],
|
|
26
|
+
"engines": {
|
|
27
|
+
"node": ">=20.0.0"
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "node node_modules/@athenna/tsconfig/src/build.js",
|
|
31
|
+
"lint:fix": "eslint \"{bin,src,tests}/**/*.ts\" --fix",
|
|
32
|
+
"test": "npm run --silent lint:fix && node --enable-source-maps --import=@athenna/tsconfig bin/test.ts",
|
|
33
|
+
"test:debug": "cross-env NODE_DEBUG=athenna:* node --inspect --enable-source-maps --import=@athenna/tsconfig bin/test.ts",
|
|
34
|
+
"test:coverage": "c8 npm run --silent test"
|
|
35
|
+
},
|
|
36
|
+
"files": [
|
|
37
|
+
"src/*.js",
|
|
38
|
+
"src/*.d.ts",
|
|
39
|
+
"src/**/*.js",
|
|
40
|
+
"src/**/*.d.ts",
|
|
41
|
+
"templates",
|
|
42
|
+
"configurer"
|
|
43
|
+
],
|
|
44
|
+
"type": "module",
|
|
45
|
+
"main": "./src/index.js",
|
|
46
|
+
"types": "./src/index.d.ts",
|
|
47
|
+
"exports": {
|
|
48
|
+
".": "./src/index.js",
|
|
49
|
+
"./types": "./src/types/index.js",
|
|
50
|
+
"./package": "./package.json",
|
|
51
|
+
"./package.json": "./package.json",
|
|
52
|
+
"./testing/plugins": "./src/testing/plugins/index.js",
|
|
53
|
+
"./kernels/HttpKernel": "./src/kernels/HttpKernel.js",
|
|
54
|
+
"./handlers/HttpExceptionHandler": "./src/handlers/HttpExceptionHandler.js",
|
|
55
|
+
"./providers/HttpRouteProvider": "./src/providers/HttpRouteProvider.js",
|
|
56
|
+
"./providers/HttpServerProvider": "./src/providers/HttpServerProvider.js",
|
|
57
|
+
"./commands/RouteListCommand": "./src/commands/RouteListCommand.js",
|
|
58
|
+
"./commands/MakeControllerCommand": "./src/commands/MakeControllerCommand.js",
|
|
59
|
+
"./commands/MakeMiddlewareCommand": "./src/commands/MakeMiddlewareCommand.js",
|
|
60
|
+
"./commands/MakeTerminatorCommand": "./src/commands/MakeTerminatorCommand.js",
|
|
61
|
+
"./commands/MakeInterceptorCommand": "./src/commands/MakeInterceptorCommand.js"
|
|
62
|
+
},
|
|
63
|
+
"imports": {
|
|
64
|
+
"#bin/*": "./bin/*.js",
|
|
65
|
+
"#bin": "./bin/index.js",
|
|
66
|
+
"#src/*": "./src/*.js",
|
|
67
|
+
"#src": "./src/index.js",
|
|
68
|
+
"#src/types": "./src/types/index.js",
|
|
69
|
+
"#src/debug": "./src/debug/index.js",
|
|
70
|
+
"#tests/*": "./tests/*.js",
|
|
71
|
+
"#tests": "./tests/index.js"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"@athenna/artisan": "^4.13.0",
|
|
75
|
+
"@athenna/common": "^4.17.2",
|
|
76
|
+
"@athenna/config": "^4.6.0",
|
|
77
|
+
"@athenna/ioc": "^4.6.0",
|
|
78
|
+
"@athenna/logger": "^4.7.0",
|
|
79
|
+
"@athenna/test": "^4.11.0",
|
|
80
|
+
"@athenna/tsconfig": "^4.8.2",
|
|
81
|
+
"@athenna/view": "^4.5.0",
|
|
82
|
+
"@fastify/cors": "^8.4.0",
|
|
83
|
+
"@fastify/helmet": "^11.1.1",
|
|
84
|
+
"@fastify/rate-limit": "^8.0.3",
|
|
85
|
+
"@fastify/swagger": "^8.11.0",
|
|
86
|
+
"@fastify/swagger-ui": "^1.10.0",
|
|
87
|
+
"@typescript-eslint/eslint-plugin": "^6.7.4",
|
|
88
|
+
"@typescript-eslint/parser": "^6.7.4",
|
|
89
|
+
"commitizen": "^4.2.6",
|
|
90
|
+
"cz-conventional-changelog": "^3.3.0",
|
|
91
|
+
"eslint": "^8.36.0",
|
|
92
|
+
"eslint-config-prettier": "^8.8.0",
|
|
93
|
+
"eslint-config-standard": "^17.0.0",
|
|
94
|
+
"eslint-plugin-import": "^2.27.5",
|
|
95
|
+
"eslint-plugin-n": "^15.6.1",
|
|
96
|
+
"eslint-plugin-prettier": "^4.2.1",
|
|
97
|
+
"eslint-plugin-promise": "^6.1.1",
|
|
98
|
+
"foreground-child": "^2.0.0",
|
|
99
|
+
"husky": "^3.1.0",
|
|
100
|
+
"lint-staged": "^12.5.0",
|
|
101
|
+
"prettier": "^2.8.7"
|
|
102
|
+
},
|
|
103
|
+
"c8": {
|
|
104
|
+
"all": true,
|
|
105
|
+
"include": [
|
|
106
|
+
"src/**/*.ts"
|
|
25
107
|
],
|
|
26
|
-
"
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
"test:debug": "cross-env NODE_DEBUG=athenna:* sh node --inspect bin/test.ts",
|
|
31
|
-
"test:coverage": "c8 npm run --silent test"
|
|
32
|
-
},
|
|
33
|
-
"files": [
|
|
34
|
-
"src/*.js",
|
|
35
|
-
"src/*.d.ts",
|
|
36
|
-
"src/**/*.js",
|
|
37
|
-
"src/**/*.d.ts",
|
|
38
|
-
"templates",
|
|
39
|
-
"configurer"
|
|
108
|
+
"exclude": [
|
|
109
|
+
"src/types/*",
|
|
110
|
+
"src/exceptions/*",
|
|
111
|
+
"src/commands/*"
|
|
40
112
|
],
|
|
41
|
-
"
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
"
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
|
|
80
|
-
"@fastify/swagger": "^8.1.0",
|
|
81
|
-
"@fastify/swagger-ui": "^1.1.0",
|
|
82
|
-
"@typescript-eslint/eslint-plugin": "^5.56.0",
|
|
83
|
-
"@typescript-eslint/parser": "^5.56.0",
|
|
84
|
-
"c8": "^7.12.0",
|
|
85
|
-
"commitizen": "^4.2.6",
|
|
86
|
-
"cz-conventional-changelog": "^3.3.0",
|
|
87
|
-
"eslint": "^8.36.0",
|
|
88
|
-
"eslint-config-prettier": "^8.8.0",
|
|
89
|
-
"eslint-config-standard": "^17.0.0",
|
|
90
|
-
"eslint-plugin-import": "^2.27.5",
|
|
91
|
-
"eslint-plugin-n": "^15.6.1",
|
|
92
|
-
"eslint-plugin-prettier": "^4.2.1",
|
|
93
|
-
"eslint-plugin-promise": "^6.1.1",
|
|
94
|
-
"husky": "^3.1.0",
|
|
95
|
-
"lint-staged": "^12.5.0",
|
|
96
|
-
"prettier": "^2.8.7",
|
|
97
|
-
"reflect-metadata": "^0.1.13",
|
|
98
|
-
"rimraf": "^5.0.1",
|
|
99
|
-
"ts-node": "^10.9.1",
|
|
100
|
-
"typescript": "^5.0.2"
|
|
101
|
-
},
|
|
102
|
-
"c8": {
|
|
103
|
-
"all": true,
|
|
104
|
-
"include": [
|
|
105
|
-
"src/**/*.ts"
|
|
106
|
-
],
|
|
107
|
-
"exclude": [
|
|
108
|
-
"src/types/*",
|
|
109
|
-
"src/exceptions/*",
|
|
110
|
-
"src/commands/*"
|
|
111
|
-
],
|
|
112
|
-
"reporter": [
|
|
113
|
-
"text-summary",
|
|
114
|
-
"html"
|
|
115
|
-
],
|
|
116
|
-
"report-dir": "./tests/coverage",
|
|
117
|
-
"check-coverage": true
|
|
118
|
-
},
|
|
119
|
-
"husky": {
|
|
120
|
-
"hooks": {
|
|
121
|
-
"prepare-commit-msg": "lint-staged && exec < /dev/tty && git cz --hook || true"
|
|
113
|
+
"reporter": [
|
|
114
|
+
"text-summary",
|
|
115
|
+
"html"
|
|
116
|
+
],
|
|
117
|
+
"report-dir": "./tests/coverage",
|
|
118
|
+
"check-coverage": true
|
|
119
|
+
},
|
|
120
|
+
"husky": {
|
|
121
|
+
"hooks": {
|
|
122
|
+
"prepare-commit-msg": "lint-staged && exec < /dev/tty && git cz --hook || true"
|
|
123
|
+
}
|
|
124
|
+
},
|
|
125
|
+
"lint-staged": {
|
|
126
|
+
"*.ts": [
|
|
127
|
+
"eslint --fix",
|
|
128
|
+
"git add"
|
|
129
|
+
],
|
|
130
|
+
"*.json": [
|
|
131
|
+
"prettier --write",
|
|
132
|
+
"git add"
|
|
133
|
+
]
|
|
134
|
+
},
|
|
135
|
+
"config": {
|
|
136
|
+
"commitizen": {
|
|
137
|
+
"path": "./node_modules/cz-conventional-changelog"
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
"prettier": {
|
|
141
|
+
"singleQuote": true,
|
|
142
|
+
"trailingComma": "none",
|
|
143
|
+
"arrowParens": "avoid",
|
|
144
|
+
"endOfLine": "lf",
|
|
145
|
+
"semi": false,
|
|
146
|
+
"printWidth": 80,
|
|
147
|
+
"overrides": [
|
|
148
|
+
{
|
|
149
|
+
"files": "tests/**/*",
|
|
150
|
+
"options": {
|
|
151
|
+
"printWidth": 120
|
|
122
152
|
}
|
|
153
|
+
}
|
|
154
|
+
]
|
|
155
|
+
},
|
|
156
|
+
"eslintIgnore": [],
|
|
157
|
+
"eslintConfig": {
|
|
158
|
+
"env": {
|
|
159
|
+
"es2021": true,
|
|
160
|
+
"node": true
|
|
123
161
|
},
|
|
124
|
-
"
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
"*.json": [
|
|
130
|
-
"prettier --write",
|
|
131
|
-
"git add"
|
|
132
|
-
]
|
|
162
|
+
"globals": {
|
|
163
|
+
"ioc": true,
|
|
164
|
+
"Env": true,
|
|
165
|
+
"Path": true,
|
|
166
|
+
"Config": true
|
|
133
167
|
},
|
|
134
|
-
"
|
|
135
|
-
|
|
136
|
-
|
|
168
|
+
"plugins": [
|
|
169
|
+
"prettier",
|
|
170
|
+
"@typescript-eslint"
|
|
171
|
+
],
|
|
172
|
+
"extends": [
|
|
173
|
+
"standard",
|
|
174
|
+
"eslint:recommended",
|
|
175
|
+
"plugin:prettier/recommended",
|
|
176
|
+
"plugin:@typescript-eslint/recommended",
|
|
177
|
+
"plugin:@typescript-eslint/eslint-recommended"
|
|
178
|
+
],
|
|
179
|
+
"parser": "@typescript-eslint/parser",
|
|
180
|
+
"rules": {
|
|
181
|
+
"camelcase": "off",
|
|
182
|
+
"dot-notation": "off",
|
|
183
|
+
"prettier/prettier": "error",
|
|
184
|
+
"no-useless-constructor": "off",
|
|
185
|
+
"@typescript-eslint/no-explicit-any": "off",
|
|
186
|
+
"@typescript-eslint/no-empty-function": "off",
|
|
187
|
+
"@typescript-eslint/no-unused-vars": [
|
|
188
|
+
"error",
|
|
189
|
+
{
|
|
190
|
+
"argsIgnorePattern": "^_",
|
|
191
|
+
"varsIgnorePattern": "^_",
|
|
192
|
+
"caughtErrorsIgnorePattern": "^_"
|
|
137
193
|
}
|
|
194
|
+
]
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
"athenna": {
|
|
198
|
+
"templates": {
|
|
199
|
+
"controller": "./templates/controller.edge",
|
|
200
|
+
"interceptor": "./templates/interceptor.edge",
|
|
201
|
+
"middleware": "./templates/middleware.edge",
|
|
202
|
+
"terminator": "./templates/terminator.edge",
|
|
203
|
+
"command": "@athenna/artisan/templates/command.edge"
|
|
138
204
|
},
|
|
139
|
-
"
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
},
|
|
155
|
-
"eslintIgnore": [],
|
|
156
|
-
"eslintConfig": {
|
|
157
|
-
"env": {
|
|
158
|
-
"es2021": true,
|
|
159
|
-
"node": true
|
|
160
|
-
},
|
|
161
|
-
"globals": {
|
|
162
|
-
"ioc": true,
|
|
163
|
-
"Env": true,
|
|
164
|
-
"Path": true,
|
|
165
|
-
"Config": true
|
|
166
|
-
},
|
|
167
|
-
"plugins": [
|
|
168
|
-
"prettier",
|
|
169
|
-
"@typescript-eslint"
|
|
170
|
-
],
|
|
171
|
-
"extends": [
|
|
172
|
-
"standard",
|
|
173
|
-
"eslint:recommended",
|
|
174
|
-
"plugin:prettier/recommended",
|
|
175
|
-
"plugin:@typescript-eslint/recommended",
|
|
176
|
-
"plugin:@typescript-eslint/eslint-recommended"
|
|
177
|
-
],
|
|
178
|
-
"parser": "@typescript-eslint/parser",
|
|
179
|
-
"rules": {
|
|
180
|
-
"camelcase": "off",
|
|
181
|
-
"dot-notation": "off",
|
|
182
|
-
"prettier/prettier": "error",
|
|
183
|
-
"no-useless-constructor": "off",
|
|
184
|
-
"@typescript-eslint/no-explicit-any": "off",
|
|
185
|
-
"@typescript-eslint/no-empty-function": "off",
|
|
186
|
-
"@typescript-eslint/no-unused-vars": [
|
|
187
|
-
"error",
|
|
188
|
-
{
|
|
189
|
-
"argsIgnorePattern": "^_",
|
|
190
|
-
"varsIgnorePattern": "^_",
|
|
191
|
-
"caughtErrorsIgnorePattern": "^_"
|
|
192
|
-
}
|
|
193
|
-
]
|
|
194
|
-
}
|
|
205
|
+
"controllers": [
|
|
206
|
+
"#tests/fixtures/controllers/HelloController",
|
|
207
|
+
"#tests/fixtures/controllers/AnnotatedController"
|
|
208
|
+
],
|
|
209
|
+
"middlewares": [
|
|
210
|
+
"#tests/fixtures/middlewares/MyMiddleware",
|
|
211
|
+
"#tests/fixtures/middlewares/ImportedMiddleware"
|
|
212
|
+
],
|
|
213
|
+
"namedMiddlewares": {
|
|
214
|
+
"myMiddleware": "#tests/fixtures/middlewares/MyMiddleware",
|
|
215
|
+
"myInterceptor": "#tests/fixtures/middlewares/MyInterceptor",
|
|
216
|
+
"myTerminator": "#tests/fixtures/middlewares/MyTerminator",
|
|
217
|
+
"not-found-middleware": "#tests/fixtures/middlewares/AnnotatedMiddleware",
|
|
218
|
+
"not-found-interceptor": "#tests/fixtures/middlewares/AnnotatedInterceptor",
|
|
219
|
+
"not-found-terminator": "#tests/fixtures/middlewares/AnnotatedTerminator"
|
|
195
220
|
},
|
|
196
|
-
"
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
"services": [],
|
|
206
|
-
"providers": [],
|
|
207
|
-
"controllers": [
|
|
208
|
-
"#tests/fixtures/controllers/HelloController",
|
|
209
|
-
"#tests/fixtures/controllers/AnnotatedController"
|
|
210
|
-
],
|
|
211
|
-
"middlewares": [
|
|
212
|
-
"#tests/fixtures/middlewares/MyMiddleware",
|
|
213
|
-
"#tests/fixtures/middlewares/ImportedMiddleware"
|
|
214
|
-
],
|
|
215
|
-
"namedMiddlewares": {
|
|
216
|
-
"myMiddleware": "#tests/fixtures/middlewares/MyMiddleware",
|
|
217
|
-
"myInterceptor": "#tests/fixtures/middlewares/MyInterceptor",
|
|
218
|
-
"myTerminator": "#tests/fixtures/middlewares/MyTerminator",
|
|
219
|
-
"not-found-middleware": "#tests/fixtures/middlewares/AnnotatedMiddleware",
|
|
220
|
-
"not-found-interceptor": "#tests/fixtures/middlewares/AnnotatedInterceptor",
|
|
221
|
-
"not-found-terminator": "#tests/fixtures/middlewares/AnnotatedTerminator"
|
|
222
|
-
},
|
|
223
|
-
"globalMiddlewares": [
|
|
224
|
-
"#tests/fixtures/middlewares/MyMiddleware",
|
|
225
|
-
"#tests/fixtures/middlewares/MyInterceptor",
|
|
226
|
-
"#tests/fixtures/middlewares/MyTerminator",
|
|
227
|
-
"#tests/fixtures/middlewares/AnnotatedGlobalMiddleware",
|
|
228
|
-
"#tests/fixtures/middlewares/AnnotatedGlobalInterceptor",
|
|
229
|
-
"#tests/fixtures/middlewares/AnnotatedGlobalTerminator"
|
|
230
|
-
],
|
|
231
|
-
"commands": {
|
|
232
|
-
"route:list": {
|
|
233
|
-
"path": "#src/commands/RouteListCommand",
|
|
234
|
-
"route": "./tests/fixtures/routes/http.js",
|
|
235
|
-
"kernel": "./tests/fixtures/kernels/HttpKernel.js"
|
|
236
|
-
},
|
|
237
|
-
"make:controller": "#src/commands/MakeControllerCommand",
|
|
238
|
-
"make:interceptor": "#src/commands/MakeInterceptorCommand",
|
|
239
|
-
"make:middleware": "#src/commands/MakeMiddlewareCommand",
|
|
240
|
-
"make:terminator": "#src/commands/MakeTerminatorCommand"
|
|
241
|
-
}
|
|
242
|
-
}
|
|
221
|
+
"globalMiddlewares": [
|
|
222
|
+
"#tests/fixtures/middlewares/MyMiddleware",
|
|
223
|
+
"#tests/fixtures/middlewares/MyInterceptor",
|
|
224
|
+
"#tests/fixtures/middlewares/MyTerminator",
|
|
225
|
+
"#tests/fixtures/middlewares/AnnotatedGlobalMiddleware",
|
|
226
|
+
"#tests/fixtures/middlewares/AnnotatedGlobalInterceptor",
|
|
227
|
+
"#tests/fixtures/middlewares/AnnotatedGlobalTerminator"
|
|
228
|
+
]
|
|
229
|
+
}
|
|
243
230
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
+
import { sep } from 'node:path';
|
|
9
10
|
import { Config } from '@athenna/config';
|
|
10
11
|
import { Module } from '@athenna/common';
|
|
11
12
|
import { BaseCommand } from '@athenna/artisan';
|
|
@@ -45,7 +46,7 @@ export class RouteListCommand extends BaseCommand {
|
|
|
45
46
|
* Resolve the http routes file.
|
|
46
47
|
*/
|
|
47
48
|
async resolveRoute() {
|
|
48
|
-
await Module.resolve(Config.get('rc.commands.route:list.route', '#routes/http'),
|
|
49
|
+
await Module.resolve(Config.get('rc.commands.route:list.route', '#routes/http'), this.getParentURL());
|
|
49
50
|
}
|
|
50
51
|
/**
|
|
51
52
|
* Get the http kernel module from RC file or resolve the default one.
|
|
@@ -54,6 +55,12 @@ export class RouteListCommand extends BaseCommand {
|
|
|
54
55
|
if (!Config.exists('rc.commands.route:list.kernel')) {
|
|
55
56
|
return HttpKernel;
|
|
56
57
|
}
|
|
57
|
-
return Module.resolve(Config.get('rc.commands.route:list.kernel'),
|
|
58
|
+
return Module.resolve(Config.get('rc.commands.route:list.kernel'), this.getParentURL());
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Get the parent URL of the project.
|
|
62
|
+
*/
|
|
63
|
+
getParentURL() {
|
|
64
|
+
return Config.get('rc.parentURL', Path.toHref(Path.pwd() + sep));
|
|
58
65
|
}
|
|
59
66
|
}
|
package/src/context/Request.js
CHANGED
package/src/index.d.ts
CHANGED
|
@@ -31,7 +31,7 @@ declare module 'fastify' {
|
|
|
31
31
|
operationId?: string;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
export * from '
|
|
34
|
+
export * from '#src/types';
|
|
35
35
|
export * from '#src/context/Request';
|
|
36
36
|
export * from '#src/context/Response';
|
|
37
37
|
export * from '#src/annotations/Controller';
|
package/src/index.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
export * from '
|
|
9
|
+
export * from '#src/types';
|
|
10
10
|
export * from '#src/context/Request';
|
|
11
11
|
export * from '#src/context/Response';
|
|
12
12
|
export * from '#src/annotations/Controller';
|
|
@@ -70,10 +70,6 @@ export declare class HttpKernel {
|
|
|
70
70
|
* server methods.
|
|
71
71
|
*/
|
|
72
72
|
private getGlobalMiddlewareAliasAndHandler;
|
|
73
|
-
/**
|
|
74
|
-
* Resolve the import path by meta URL and import it.
|
|
75
|
-
*/
|
|
76
|
-
private resolvePath;
|
|
77
73
|
/**
|
|
78
74
|
* Register the controllers using the meta information
|
|
79
75
|
* defined by annotations.
|
|
@@ -83,4 +79,8 @@ export declare class HttpKernel {
|
|
|
83
79
|
* Get the configuration for the given key.
|
|
84
80
|
*/
|
|
85
81
|
private getConfig;
|
|
82
|
+
/**
|
|
83
|
+
* Get the meta URL of the project.
|
|
84
|
+
*/
|
|
85
|
+
private getMeta;
|
|
86
86
|
}
|
|
@@ -11,7 +11,7 @@ import { Server } from '#src';
|
|
|
11
11
|
import { debug } from '#src/debug';
|
|
12
12
|
import { Log } from '@athenna/logger';
|
|
13
13
|
import { Config } from '@athenna/config';
|
|
14
|
-
import { isAbsolute, resolve } from 'node:path';
|
|
14
|
+
import { sep, isAbsolute, resolve } from 'node:path';
|
|
15
15
|
import { Annotation } from '@athenna/ioc';
|
|
16
16
|
import { File, Exec, Module, String } from '@athenna/common';
|
|
17
17
|
import { HttpExceptionHandler } from '#src/handlers/HttpExceptionHandler';
|
|
@@ -117,7 +117,7 @@ export class HttpKernel {
|
|
|
117
117
|
async registerControllers() {
|
|
118
118
|
const controllers = Config.get('rc.controllers', []);
|
|
119
119
|
await Exec.concurrently(controllers, async (path) => {
|
|
120
|
-
const Controller = await this.
|
|
120
|
+
const Controller = await Module.resolve(path, this.getMeta());
|
|
121
121
|
if (Annotation.isAnnotated(Controller)) {
|
|
122
122
|
this.registerUsingMeta(Controller);
|
|
123
123
|
return;
|
|
@@ -133,7 +133,7 @@ export class HttpKernel {
|
|
|
133
133
|
async registerMiddlewares() {
|
|
134
134
|
const middlewares = Config.get('rc.middlewares', []);
|
|
135
135
|
await Exec.concurrently(middlewares, async (path) => {
|
|
136
|
-
const Middleware = await this.
|
|
136
|
+
const Middleware = await Module.resolve(path, this.getMeta());
|
|
137
137
|
if (Annotation.isAnnotated(Middleware)) {
|
|
138
138
|
this.registerUsingMeta(Middleware);
|
|
139
139
|
return;
|
|
@@ -152,7 +152,7 @@ export class HttpKernel {
|
|
|
152
152
|
async registerNamedMiddlewares() {
|
|
153
153
|
const namedMiddlewares = Config.get('rc.namedMiddlewares', {});
|
|
154
154
|
await Exec.concurrently(Object.keys(namedMiddlewares), async (key) => {
|
|
155
|
-
const Middleware = await
|
|
155
|
+
const Middleware = await Module.resolve(namedMiddlewares[key], this.getMeta());
|
|
156
156
|
if (Annotation.isAnnotated(Middleware)) {
|
|
157
157
|
this.registerUsingMeta(Middleware);
|
|
158
158
|
return;
|
|
@@ -168,7 +168,7 @@ export class HttpKernel {
|
|
|
168
168
|
async registerGlobalMiddlewares() {
|
|
169
169
|
const globalMiddlewares = Config.get('rc.globalMiddlewares', []);
|
|
170
170
|
await Exec.concurrently(globalMiddlewares, async (path) => {
|
|
171
|
-
const Middleware = await this.
|
|
171
|
+
const Middleware = await Module.resolve(path, this.getMeta());
|
|
172
172
|
if (Annotation.isAnnotated(Middleware)) {
|
|
173
173
|
this.registerUsingMeta(Middleware);
|
|
174
174
|
return;
|
|
@@ -191,7 +191,7 @@ export class HttpKernel {
|
|
|
191
191
|
Server.setErrorHandler(handler.handle.bind(handler));
|
|
192
192
|
return;
|
|
193
193
|
}
|
|
194
|
-
const Handler = await this.
|
|
194
|
+
const Handler = await Module.resolve(path, this.getMeta());
|
|
195
195
|
debug('Using custom exception handler %s in HttpKernel.', Handler.name);
|
|
196
196
|
const handler = new Handler();
|
|
197
197
|
Server.setErrorHandler(handler.handle.bind(handler));
|
|
@@ -201,7 +201,7 @@ export class HttpKernel {
|
|
|
201
201
|
*/
|
|
202
202
|
async registerRoutes(path) {
|
|
203
203
|
if (path.startsWith('#')) {
|
|
204
|
-
await this.
|
|
204
|
+
await Module.resolve(path, this.getMeta());
|
|
205
205
|
return;
|
|
206
206
|
}
|
|
207
207
|
if (!isAbsolute(path)) {
|
|
@@ -210,7 +210,7 @@ export class HttpKernel {
|
|
|
210
210
|
if (!(await File.exists(path))) {
|
|
211
211
|
return;
|
|
212
212
|
}
|
|
213
|
-
await this.
|
|
213
|
+
await Module.resolve(path, this.getMeta());
|
|
214
214
|
}
|
|
215
215
|
/**
|
|
216
216
|
* Fabricate the named middlewares aliases.
|
|
@@ -264,12 +264,6 @@ export class HttpKernel {
|
|
|
264
264
|
};
|
|
265
265
|
}
|
|
266
266
|
}
|
|
267
|
-
/**
|
|
268
|
-
* Resolve the import path by meta URL and import it.
|
|
269
|
-
*/
|
|
270
|
-
resolvePath(path) {
|
|
271
|
-
return Module.resolve(`${path}?version=${Math.random()}`, Config.get('rc.meta'));
|
|
272
|
-
}
|
|
273
267
|
/**
|
|
274
268
|
* Register the controllers using the meta information
|
|
275
269
|
* defined by annotations.
|
|
@@ -302,4 +296,10 @@ export class HttpKernel {
|
|
|
302
296
|
}
|
|
303
297
|
return config;
|
|
304
298
|
}
|
|
299
|
+
/**
|
|
300
|
+
* Get the meta URL of the project.
|
|
301
|
+
*/
|
|
302
|
+
getMeta() {
|
|
303
|
+
return Config.get('rc.parentURL', Path.toHref(Path.pwd() + sep));
|
|
304
|
+
}
|
|
305
305
|
}
|
package/src/router/Route.js
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* For the full copyright and license information, please view the LICENSE
|
|
7
7
|
* file that was distributed with this source code.
|
|
8
8
|
*/
|
|
9
|
-
import { Is, Route as RouteHelper } from '@athenna/common';
|
|
9
|
+
import { Is, Options, Route as RouteHelper } from '@athenna/common';
|
|
10
10
|
import { UndefinedMethodException } from '#src/exceptions/UndefinedMethodException';
|
|
11
11
|
import { NotFoundMiddlewareException } from '#src/exceptions/NotFoundMiddlewareException';
|
|
12
12
|
export class Route {
|
|
@@ -362,7 +362,10 @@ export class Route {
|
|
|
362
362
|
* })
|
|
363
363
|
* ```
|
|
364
364
|
*/
|
|
365
|
-
response(statusCode, response
|
|
365
|
+
response(statusCode, response) {
|
|
366
|
+
response = Options.create(response, {
|
|
367
|
+
description: `Status code ${statusCode} response`
|
|
368
|
+
});
|
|
366
369
|
if (!this.route.fastify.schema.response) {
|
|
367
370
|
this.route.fastify.schema.response = {};
|
|
368
371
|
}
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
/// <reference types="node" resolution-mode="require"/>
|
|
10
10
|
import type { InjectOptions, FastifyInstance, PrintRoutesOptions, FastifyListenOptions, FastifyServerOptions, LightMyRequestChain, LightMyRequestResponse } from 'fastify';
|
|
11
|
-
import type { RouteJson, ErrorHandler, RequestHandler, InterceptHandler, TerminateHandler } from '#src/types';
|
|
11
|
+
import type { RouteJson, ErrorHandler, RequestHandler, InterceptHandler, TerminateHandler, SwaggerDocument } from '#src/types';
|
|
12
12
|
import type { AddressInfo } from 'node:net';
|
|
13
13
|
export declare class ServerImpl {
|
|
14
14
|
/**
|
|
@@ -43,13 +43,13 @@ export declare class ServerImpl {
|
|
|
43
43
|
* Get the fastify version that is running the server.
|
|
44
44
|
*/
|
|
45
45
|
getFastifyVersion(): string;
|
|
46
|
-
getSwagger():
|
|
46
|
+
getSwagger(): Promise<SwaggerDocument>;
|
|
47
47
|
getSwagger(options: {
|
|
48
48
|
yaml: true;
|
|
49
|
-
}): string
|
|
49
|
+
}): Promise<string>;
|
|
50
50
|
getSwagger(options: {
|
|
51
51
|
yaml: false;
|
|
52
|
-
}):
|
|
52
|
+
}): Promise<SwaggerDocument>;
|
|
53
53
|
/**
|
|
54
54
|
* Set the error handler to handle errors that happens inside the server.
|
|
55
55
|
*/
|
package/src/server/ServerImpl.js
CHANGED
|
@@ -54,13 +54,14 @@ export class ServerImpl {
|
|
|
54
54
|
* @fastify/swagger plugin in the server. If the plugin is not installed
|
|
55
55
|
* will return null.
|
|
56
56
|
*/
|
|
57
|
-
getSwagger(options) {
|
|
57
|
+
async getSwagger(options) {
|
|
58
58
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
59
59
|
// @ts-ignore
|
|
60
60
|
const swagger = this.fastify.swagger;
|
|
61
61
|
if (!swagger) {
|
|
62
62
|
return null;
|
|
63
63
|
}
|
|
64
|
+
await this.fastify.ready();
|
|
64
65
|
return swagger(options);
|
|
65
66
|
}
|
|
66
67
|
/**
|
package/src/types/index.d.ts
CHANGED
package/src/types/index.js
CHANGED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @athenna/http
|
|
3
|
+
*
|
|
4
|
+
* (c) João Lenon <lenon@athenna.io>
|
|
5
|
+
*
|
|
6
|
+
* For the full copyright and license information, please view the LICENSE
|
|
7
|
+
* file that was distributed with this source code.
|
|
8
|
+
*/
|
|
9
|
+
import type { OpenAPI } from 'openapi-types';
|
|
10
|
+
export type SwaggerDocument = OpenAPI.Document;
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { Controller, type Context } from '@athenna/http'
|
|
2
|
-
|
|
3
|
-
@Controller()
|
|
4
|
-
export class {{ namePascal }} {
|
|
5
|
-
public async index({ response }: Context): Promise<void> {
|
|
6
|
-
return response.status(200).send([{}])
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
public async store({ response }: Context): Promise<void> {
|
|
10
|
-
return response.status(201).send({})
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
public async show({ response }: Context): Promise<void> {
|
|
14
|
-
return response.status(200).send({})
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
public async update({ response, params }: Context): Promise<void> {
|
|
18
|
-
return response.status(200).send({ id: params.id })
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
public async delete({ response }: Context): Promise<void> {
|
|
22
|
-
return response.status(204)
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { Interceptor } from '@athenna/http'
|
|
2
|
-
import type { InterceptorContract, InterceptContext } from '@athenna/http'
|
|
3
|
-
|
|
4
|
-
@Interceptor()
|
|
5
|
-
export class {{ namePascal }} implements InterceptorContract {
|
|
6
|
-
public async intercept(ctx: InterceptContext): Promise<unknown> {
|
|
7
|
-
return ctx.body
|
|
8
|
-
}
|
|
9
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { Terminator } from '@athenna/http'
|
|
2
|
-
import type { TerminateContext, TerminatorContract } from '@athenna/http'
|
|
3
|
-
|
|
4
|
-
@Terminator()
|
|
5
|
-
export class {{ namePascal }} implements TerminatorContract {
|
|
6
|
-
public async terminate(ctx: TerminateContext): Promise<void> {}
|
|
7
|
-
}
|