@adonisjs/core 5.9.0 → 6.0.0-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 +6 -15
- package/build/commands/commands.json +1 -0
- package/build/commands/eject.d.ts +8 -0
- package/build/commands/eject.js +34 -0
- package/build/commands/{GenerateKey.d.ts → generate_key.d.ts} +3 -4
- package/build/commands/generate_key.js +47 -0
- package/build/commands/main.js +36 -0
- package/build/commands/make/_base.d.ts +6 -0
- package/build/commands/make/_base.js +19 -0
- package/build/commands/make/command.d.ts +8 -0
- package/build/commands/make/command.js +25 -0
- package/build/commands/make/controller.d.ts +12 -0
- package/build/commands/make/controller.js +57 -0
- package/build/commands/make/event.d.ts +8 -0
- package/build/commands/make/event.js +25 -0
- package/build/commands/make/listener.d.ts +10 -0
- package/build/commands/make/listener.js +48 -0
- package/build/commands/make/middleware.d.ts +8 -0
- package/build/commands/make/middleware.js +25 -0
- package/build/commands/make/provider.d.ts +8 -0
- package/build/commands/make/provider.js +25 -0
- package/build/index.d.ts +140 -0
- package/build/index.js +21 -0
- package/build/legacy/validator.d.ts +1 -0
- package/build/legacy/validator.js +1 -0
- package/build/modules/ace/commands.d.ts +26 -0
- package/build/modules/ace/commands.js +63 -0
- package/build/modules/ace/create_kernel.d.ts +3 -0
- package/build/modules/ace/create_kernel.js +33 -0
- package/build/modules/ace/kernel.d.ts +7 -0
- package/build/modules/ace/kernel.js +14 -0
- package/build/modules/ace/main.d.ts +3 -0
- package/build/modules/ace/main.js +3 -0
- package/build/modules/app.d.ts +1 -0
- package/build/modules/app.js +1 -0
- package/build/modules/bodyparser/bodyparser_middleware.d.ts +2 -0
- package/build/modules/bodyparser/bodyparser_middleware.js +2 -0
- package/build/modules/bodyparser/main.d.ts +1 -0
- package/build/modules/bodyparser/main.js +1 -0
- package/build/modules/config.d.ts +1 -0
- package/build/modules/config.js +1 -0
- package/build/modules/container.d.ts +1 -0
- package/build/modules/container.js +1 -0
- package/build/modules/encryption.d.ts +1 -0
- package/build/modules/encryption.js +1 -0
- package/build/modules/env.d.ts +1 -0
- package/build/modules/env.js +1 -0
- package/build/modules/events.d.ts +1 -0
- package/build/modules/events.js +1 -0
- package/build/modules/hash/define_config.d.ts +15 -0
- package/build/modules/hash/define_config.js +19 -0
- package/build/modules/hash/drivers_collection.d.ts +9 -0
- package/build/modules/hash/drivers_collection.js +22 -0
- package/build/modules/hash/main.d.ts +2 -0
- package/build/modules/hash/main.js +2 -0
- package/build/modules/http.d.ts +1 -0
- package/build/modules/http.js +1 -0
- package/build/modules/logger.d.ts +1 -0
- package/build/modules/logger.js +1 -0
- package/build/providers/app_provider.d.ts +16 -0
- package/build/providers/app_provider.js +74 -0
- package/build/providers/hash_provider.d.ts +9 -0
- package/build/providers/hash_provider.js +29 -0
- package/build/providers/http_provider.d.ts +9 -0
- package/build/providers/http_provider.js +36 -0
- package/build/services/ace.d.ts +3 -0
- package/build/services/ace.js +6 -0
- package/build/services/app.d.ts +4 -12
- package/build/services/app.js +5 -12
- package/build/services/config.d.ts +3 -3
- package/build/services/config.js +6 -12
- package/build/services/emitter.d.ts +3 -0
- package/build/services/emitter.js +7 -0
- package/build/services/encryption.d.ts +3 -3
- package/build/services/encryption.js +7 -12
- package/build/services/hash.d.ts +3 -3
- package/build/services/hash.js +7 -12
- package/build/services/logger.d.ts +3 -0
- package/build/services/logger.js +7 -0
- package/build/services/router.d.ts +3 -0
- package/build/services/router.js +7 -0
- package/build/services/server.d.ts +3 -0
- package/build/services/server.js +7 -0
- package/build/services/test_utils.d.ts +3 -0
- package/build/services/test_utils.js +6 -0
- package/build/src/debug.d.ts +3 -0
- package/build/src/debug.js +2 -0
- package/build/src/helpers/is.d.ts +2 -0
- package/build/src/helpers/is.js +2 -0
- package/build/src/helpers/main.d.ts +2 -0
- package/build/src/helpers/main.js +2 -0
- package/build/src/helpers/string.d.ts +17 -0
- package/build/src/helpers/string.js +26 -0
- package/build/src/helpers/string_builder.d.ts +23 -0
- package/build/src/helpers/string_builder.js +86 -0
- package/build/src/helpers/types.d.ts +24 -0
- package/build/src/helpers/types.js +29 -0
- package/build/src/ignitor/ace.d.ts +8 -0
- package/build/src/ignitor/ace.js +31 -0
- package/build/src/ignitor/http.d.ts +10 -0
- package/build/src/ignitor/http.js +62 -0
- package/build/src/ignitor/main.d.ts +17 -0
- package/build/src/ignitor/main.js +45 -0
- package/build/src/ignitor/test.d.ts +8 -0
- package/build/src/ignitor/test.js +18 -0
- package/build/src/test_utils/http.d.ts +10 -0
- package/build/src/test_utils/http.js +42 -0
- package/build/src/test_utils/main.d.ts +19 -0
- package/build/src/test_utils/main.js +33 -0
- package/build/src/types.d.ts +63 -0
- package/build/src/types.js +1 -0
- package/build/stubs/index.d.ts +1 -0
- package/build/stubs/index.js +2 -0
- package/build/stubs/make/command/main.stub +19 -0
- package/build/stubs/make/controller/api.stub +33 -0
- package/build/stubs/make/controller/main.stub +9 -0
- package/build/stubs/make/controller/resource.stub +43 -0
- package/build/stubs/make/event/main.stub +15 -0
- package/build/stubs/make/listener/for_event.stub +13 -0
- package/build/stubs/make/listener/main.stub +7 -0
- package/build/stubs/make/middleware/main.stub +22 -0
- package/build/stubs/make/provider/main.stub +35 -0
- package/build/types/ace.d.ts +5 -0
- package/build/types/ace.js +1 -0
- package/build/types/app.d.ts +1 -0
- package/build/types/app.js +1 -0
- package/build/types/bodyparser.d.ts +1 -0
- package/build/types/bodyparser.js +1 -0
- package/build/types/container.d.ts +1 -0
- package/build/types/container.js +1 -0
- package/build/types/encryption.d.ts +1 -0
- package/build/types/encryption.js +1 -0
- package/build/types/events.d.ts +1 -0
- package/build/types/events.js +1 -0
- package/build/types/hash.d.ts +1 -0
- package/build/types/hash.js +1 -0
- package/build/types/http.d.ts +1 -0
- package/build/types/http.js +1 -0
- package/build/types/logger.d.ts +1 -0
- package/build/types/logger.js +1 -0
- package/package.json +226 -245
- package/build/adonis-typings/ace.d.ts +0 -5
- package/build/adonis-typings/ace.js +0 -8
- package/build/adonis-typings/assets-manager.d.ts +0 -92
- package/build/adonis-typings/assets-manager.js +0 -8
- package/build/adonis-typings/container.d.ts +0 -14
- package/build/adonis-typings/container.js +0 -8
- package/build/adonis-typings/cors.d.ts +0 -15
- package/build/adonis-typings/cors.js +0 -8
- package/build/adonis-typings/exception-handler.d.ts +0 -31
- package/build/adonis-typings/exception-handler.js +0 -8
- package/build/adonis-typings/health-check.d.ts +0 -40
- package/build/adonis-typings/health-check.js +0 -8
- package/build/adonis-typings/index.d.ts +0 -17
- package/build/adonis-typings/index.js +0 -25
- package/build/adonis-typings/static.d.ts +0 -15
- package/build/adonis-typings/static.js +0 -8
- package/build/adonis-typings/test-utils.d.ts +0 -24
- package/build/adonis-typings/test-utils.js +0 -8
- package/build/adonis-typings/tests.d.ts +0 -13
- package/build/adonis-typings/tests.js +0 -11
- package/build/commands/DumpRc.d.ts +0 -13
- package/build/commands/DumpRc.js +0 -33
- package/build/commands/GenerateKey.js +0 -25
- package/build/commands/ListRoutes/Renderers/Base.d.ts +0 -31
- package/build/commands/ListRoutes/Renderers/Base.js +0 -70
- package/build/commands/ListRoutes/Renderers/PrettyRenderer.d.ts +0 -51
- package/build/commands/ListRoutes/Renderers/PrettyRenderer.js +0 -135
- package/build/commands/ListRoutes/Renderers/TableRenderer.d.ts +0 -36
- package/build/commands/ListRoutes/Renderers/TableRenderer.js +0 -137
- package/build/commands/ListRoutes/index.d.ts +0 -75
- package/build/commands/ListRoutes/index.js +0 -166
- package/build/commands/index.d.ts +0 -2
- package/build/commands/index.js +0 -15
- package/build/config.d.ts +0 -2
- package/build/config.js +0 -15
- package/build/instructions.js +0 -81
- package/build/providers/AppProvider.d.ts +0 -68
- package/build/providers/AppProvider.js +0 -201
- package/build/services/base.d.ts +0 -3
- package/build/services/base.js +0 -23
- package/build/services/bodyparser.d.ts +0 -2
- package/build/services/bodyparser.js +0 -12
- package/build/services/drive.d.ts +0 -3
- package/build/services/drive.js +0 -12
- package/build/services/event.d.ts +0 -3
- package/build/services/event.js +0 -12
- package/build/services/healthChecks.d.ts +0 -3
- package/build/services/healthChecks.js +0 -12
- package/build/services/httpContext.d.ts +0 -3
- package/build/services/httpContext.js +0 -12
- package/build/services/route.d.ts +0 -3
- package/build/services/route.js +0 -12
- package/build/services/validator.d.ts +0 -3
- package/build/services/validator.js +0 -12
- package/build/src/AssetsManager/Drivers/Base.d.ts +0 -27
- package/build/src/AssetsManager/Drivers/Base.js +0 -66
- package/build/src/AssetsManager/Drivers/Encore.d.ts +0 -58
- package/build/src/AssetsManager/Drivers/Encore.js +0 -93
- package/build/src/AssetsManager/Drivers/Fake.d.ts +0 -38
- package/build/src/AssetsManager/Drivers/Fake.js +0 -61
- package/build/src/AssetsManager/Drivers/Vite.d.ts +0 -84
- package/build/src/AssetsManager/Drivers/Vite.js +0 -139
- package/build/src/AssetsManager/index.d.ts +0 -87
- package/build/src/AssetsManager/index.js +0 -184
- package/build/src/Bindings/Repl.d.ts +0 -8
- package/build/src/Bindings/Repl.js +0 -90
- package/build/src/Bindings/Tests.d.ts +0 -7
- package/build/src/Bindings/Tests.js +0 -66
- package/build/src/HealthCheck/Checkers/AppKey.d.ts +0 -6
- package/build/src/HealthCheck/Checkers/AppKey.js +0 -60
- package/build/src/HealthCheck/Checkers/Env.d.ts +0 -6
- package/build/src/HealthCheck/Checkers/Env.js +0 -42
- package/build/src/HealthCheck/index.d.ts +0 -48
- package/build/src/HealthCheck/index.js +0 -99
- package/build/src/Hooks/Cors/index.d.ts +0 -70
- package/build/src/Hooks/Cors/index.js +0 -314
- package/build/src/Hooks/Static/index.d.ts +0 -18
- package/build/src/Hooks/Static/index.js +0 -66
- package/build/src/HttpExceptionHandler/index.d.ts +0 -82
- package/build/src/HttpExceptionHandler/index.js +0 -213
- package/build/src/Ignitor/Ace/App/index.d.ts +0 -60
- package/build/src/Ignitor/Ace/App/index.js +0 -236
- package/build/src/Ignitor/Ace/Exceptions/index.d.ts +0 -4
- package/build/src/Ignitor/Ace/Exceptions/index.js +0 -19
- package/build/src/Ignitor/Ace/GenerateManifest/index.d.ts +0 -28
- package/build/src/Ignitor/Ace/GenerateManifest/index.js +0 -75
- package/build/src/Ignitor/Ace/index.d.ts +0 -11
- package/build/src/Ignitor/Ace/index.js +0 -36
- package/build/src/Ignitor/HttpServer/index.d.ts +0 -56
- package/build/src/Ignitor/HttpServer/index.js +0 -127
- package/build/src/Ignitor/Kernel/index.d.ts +0 -56
- package/build/src/Ignitor/Kernel/index.js +0 -123
- package/build/src/Ignitor/SignalsListener/index.d.ts +0 -23
- package/build/src/Ignitor/SignalsListener/index.js +0 -66
- package/build/src/Ignitor/index.d.ts +0 -32
- package/build/src/Ignitor/index.js +0 -58
- package/build/src/TestUtils/HttpServer/index.d.ts +0 -27
- package/build/src/TestUtils/HttpServer/index.js +0 -56
- package/build/src/TestUtils/index.d.ts +0 -24
- package/build/src/TestUtils/index.js +0 -43
- package/build/src/utils/index.d.ts +0 -18
- package/build/src/utils/index.js +0 -82
- package/build/standalone.d.ts +0 -9
- package/build/standalone.js +0 -52
- package/build/templates/config/app.txt +0 -303
- package/build/templates/config/bodyparser.txt +0 -211
- package/build/templates/config/cors.txt +0 -134
- package/build/templates/config/drive.txt +0 -149
- package/build/templates/config/hash.txt +0 -96
- package/build/templates/config/static.txt +0 -89
- package/build/templates/contracts/drive.txt +0 -13
- package/build/templates/contracts/env.txt +0 -24
- package/build/templates/contracts/events.txt +0 -31
- package/build/templates/contracts/hash.txt +0 -13
- package/build/templates/env.txt +0 -31
|
@@ -1,314 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/core
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.Cors = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* List of default exposed headers.
|
|
14
|
-
*/
|
|
15
|
-
const SIMPLE_EXPOSE_HEADERS = [
|
|
16
|
-
'cache-control',
|
|
17
|
-
'content-language',
|
|
18
|
-
'content-type',
|
|
19
|
-
'expires',
|
|
20
|
-
'last-modified',
|
|
21
|
-
'pragma',
|
|
22
|
-
];
|
|
23
|
-
/**
|
|
24
|
-
* The Cors middleware class to handle preflight request as per the CORS
|
|
25
|
-
* RFC https://www.w3.org/TR/cors/.
|
|
26
|
-
*
|
|
27
|
-
* This is a functional middleware and shared among all requests. So make
|
|
28
|
-
* sure not to set request specific instance properties.
|
|
29
|
-
*/
|
|
30
|
-
class Cors {
|
|
31
|
-
constructor(options) {
|
|
32
|
-
this.options = options;
|
|
33
|
-
this.normalizeOptions();
|
|
34
|
-
}
|
|
35
|
-
/**
|
|
36
|
-
* Normalize config options
|
|
37
|
-
*/
|
|
38
|
-
normalizeOptions() {
|
|
39
|
-
/**
|
|
40
|
-
* Convert all headers to lowercase
|
|
41
|
-
*/
|
|
42
|
-
this.options.exposeHeaders = this.options.exposeHeaders.map((header) => header.toLowerCase());
|
|
43
|
-
const hasExtraHeaders = this.options.exposeHeaders.find((header) => {
|
|
44
|
-
return SIMPLE_EXPOSE_HEADERS.indexOf(header) === -1;
|
|
45
|
-
});
|
|
46
|
-
/**
|
|
47
|
-
* If expose headers doesn't have extra headers, then empty the list
|
|
48
|
-
*/
|
|
49
|
-
if (!hasExtraHeaders) {
|
|
50
|
-
this.options.exposeHeaders = [];
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* A pre-computed function to know if CORS is enabled for current request or not
|
|
54
|
-
*/
|
|
55
|
-
if (typeof this.options.enabled === 'function') {
|
|
56
|
-
this.isEnabled = this.options.enabled;
|
|
57
|
-
}
|
|
58
|
-
else {
|
|
59
|
-
this.isEnabled = () => this.options.enabled;
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
/**
|
|
63
|
-
* Computes the origin for the current request based upon the
|
|
64
|
-
* user config.
|
|
65
|
-
*
|
|
66
|
-
* Origin match is always case sensitive
|
|
67
|
-
*/
|
|
68
|
-
computeResponseOrigin(origin, ctx) {
|
|
69
|
-
let allowedOrigins = this.options.origin;
|
|
70
|
-
/**
|
|
71
|
-
* If the `origin` value inside user config is a function, we
|
|
72
|
-
* call that function and use the return value as the
|
|
73
|
-
* new config value.
|
|
74
|
-
*/
|
|
75
|
-
if (typeof allowedOrigins === 'function') {
|
|
76
|
-
allowedOrigins = allowedOrigins(origin, ctx);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* If true, then allow the current origin
|
|
80
|
-
*/
|
|
81
|
-
if (allowedOrigins === true) {
|
|
82
|
-
return origin;
|
|
83
|
-
}
|
|
84
|
-
/**
|
|
85
|
-
* False, disallows all origins
|
|
86
|
-
*/
|
|
87
|
-
if (allowedOrigins === false) {
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
/**
|
|
91
|
-
* Wildcard allows the current origin. However, it also indicates
|
|
92
|
-
* the browser that all origins are allowed.
|
|
93
|
-
*
|
|
94
|
-
* Fundamentaly `*` and `true` are not same, though they both allows
|
|
95
|
-
* the same origin.
|
|
96
|
-
*/
|
|
97
|
-
if (allowedOrigins === '*') {
|
|
98
|
-
/**
|
|
99
|
-
* Setting `Access-Control-Allow-Origin=*` along with `Access-Control-Allow-Credentials=true`
|
|
100
|
-
* isn't allowed. So in that case, we return the value of the current origin and not the
|
|
101
|
-
* wildcard identifier.
|
|
102
|
-
*/
|
|
103
|
-
return this.options.credentials === true ? origin : '*';
|
|
104
|
-
}
|
|
105
|
-
/**
|
|
106
|
-
* Find the matching origin, if value is an array
|
|
107
|
-
*/
|
|
108
|
-
if (Array.isArray(allowedOrigins)) {
|
|
109
|
-
if (allowedOrigins.find((allowedOrigin) => allowedOrigin === origin)) {
|
|
110
|
-
return origin;
|
|
111
|
-
}
|
|
112
|
-
return null;
|
|
113
|
-
}
|
|
114
|
-
/**
|
|
115
|
-
* Find the matching origin, if value is a comma seperated string
|
|
116
|
-
*/
|
|
117
|
-
if (allowedOrigins.split(',').find((allowedOrigin) => allowedOrigin === origin)) {
|
|
118
|
-
return origin;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Nothing is allowed
|
|
122
|
-
*/
|
|
123
|
-
return null;
|
|
124
|
-
}
|
|
125
|
-
/**
|
|
126
|
-
* Returns an array of headers allowed based upon user config
|
|
127
|
-
* and request headers.
|
|
128
|
-
*
|
|
129
|
-
* The array items are casted to lowercase for case insensitive
|
|
130
|
-
* match.
|
|
131
|
-
*/
|
|
132
|
-
computedAllowedHeaders(headers, ctx) {
|
|
133
|
-
let allowedHeaders = this.options.headers;
|
|
134
|
-
/**
|
|
135
|
-
* Compute allowed headers by calling the config function.
|
|
136
|
-
*/
|
|
137
|
-
if (typeof allowedHeaders === 'function') {
|
|
138
|
-
allowedHeaders = allowedHeaders(headers, ctx);
|
|
139
|
-
}
|
|
140
|
-
/**
|
|
141
|
-
* Allow current set of headers, when `allowedHeaders = true`
|
|
142
|
-
*/
|
|
143
|
-
if (allowedHeaders === true) {
|
|
144
|
-
return headers.map((header) => header.toLowerCase());
|
|
145
|
-
}
|
|
146
|
-
/**
|
|
147
|
-
* Disallow all headers
|
|
148
|
-
*/
|
|
149
|
-
if (allowedHeaders === false) {
|
|
150
|
-
return [];
|
|
151
|
-
}
|
|
152
|
-
/**
|
|
153
|
-
* Allow explicitly define headers as an array of comma seperated
|
|
154
|
-
* string literal.
|
|
155
|
-
*/
|
|
156
|
-
if (Array.isArray(allowedHeaders)) {
|
|
157
|
-
return allowedHeaders.map((header) => header.toLowerCase());
|
|
158
|
-
}
|
|
159
|
-
return allowedHeaders.split(',').map((header) => header.toLowerCase());
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* Sets the `Access-Control-Allow-Origin` header
|
|
163
|
-
*/
|
|
164
|
-
setOrigin(response, allowedOrigin) {
|
|
165
|
-
response.header('Access-Control-Allow-Origin', allowedOrigin);
|
|
166
|
-
}
|
|
167
|
-
/**
|
|
168
|
-
* Setting `Access-Control-Expose-Headers` headers, when custom headers
|
|
169
|
-
* are defined. If no custom headers are defined, then simple response
|
|
170
|
-
* headers are used instead.
|
|
171
|
-
*/
|
|
172
|
-
setExposedHeaders(response) {
|
|
173
|
-
if (this.options.exposeHeaders.length) {
|
|
174
|
-
response.header('Access-Control-Expose-Headers', this.options.exposeHeaders.join(','));
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
/**
|
|
178
|
-
* Allows `Access-Control-Allow-Credentials` when enabled inside the user
|
|
179
|
-
* config.
|
|
180
|
-
*/
|
|
181
|
-
setCredentials(response) {
|
|
182
|
-
if (this.options.credentials === true) {
|
|
183
|
-
response.header('Access-Control-Allow-Credentials', 'true');
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Set `Access-Control-Allow-Methods` header.
|
|
188
|
-
*/
|
|
189
|
-
setAllowMethods(response) {
|
|
190
|
-
response.header('Access-Control-Allow-Methods', this.options.methods.join(','));
|
|
191
|
-
}
|
|
192
|
-
/**
|
|
193
|
-
* Set `Access-Control-Allow-Headers` header.
|
|
194
|
-
*/
|
|
195
|
-
setAllowHeaders(response, allowedHeaders) {
|
|
196
|
-
response.header('Access-Control-Allow-Headers', allowedHeaders.join(','));
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* Set `Access-Control-Max-Age` header.
|
|
200
|
-
*/
|
|
201
|
-
setMaxAge(response) {
|
|
202
|
-
if (this.options.maxAge) {
|
|
203
|
-
response.header('Access-Control-Max-Age', this.options.maxAge);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
/**
|
|
207
|
-
* Ends the preflight request with 204 status code
|
|
208
|
-
*/
|
|
209
|
-
endPreFlight(response) {
|
|
210
|
-
response.status(204).send(null);
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Handle HTTP request for CORS. This method is binded as a before hook
|
|
214
|
-
* to the HTTP server.
|
|
215
|
-
*/
|
|
216
|
-
async handle(ctx) {
|
|
217
|
-
/**
|
|
218
|
-
* Return early when CORS is not enabled for the current request
|
|
219
|
-
*/
|
|
220
|
-
if (!this.isEnabled(ctx.request, ctx)) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
const origin = ctx.request.header('origin');
|
|
224
|
-
const isOptions = ctx.request.method() === 'OPTIONS';
|
|
225
|
-
/**
|
|
226
|
-
* If their is no Origin header present, then let the user-agent handle
|
|
227
|
-
* this situation, since the request is outside the scope of CORS.
|
|
228
|
-
*/
|
|
229
|
-
if (!origin) {
|
|
230
|
-
return;
|
|
231
|
-
}
|
|
232
|
-
const allowedOrigin = this.computeResponseOrigin(origin, ctx);
|
|
233
|
-
/**
|
|
234
|
-
* If origin is not allowed, then we don't set any of the cors headers
|
|
235
|
-
*/
|
|
236
|
-
if (!allowedOrigin) {
|
|
237
|
-
/**
|
|
238
|
-
* Also end the OPTIONS request right away
|
|
239
|
-
*/
|
|
240
|
-
if (isOptions) {
|
|
241
|
-
this.endPreFlight(ctx.response);
|
|
242
|
-
}
|
|
243
|
-
return;
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Set required headers for non options request.
|
|
247
|
-
*/
|
|
248
|
-
if (!isOptions) {
|
|
249
|
-
this.setOrigin(ctx.response, allowedOrigin);
|
|
250
|
-
this.setCredentials(ctx.response);
|
|
251
|
-
this.setExposedHeaders(ctx.response);
|
|
252
|
-
return;
|
|
253
|
-
}
|
|
254
|
-
/**
|
|
255
|
-
* Everything below is for pre-flight (aka OPTIONS) request
|
|
256
|
-
*/
|
|
257
|
-
const requestMethod = ctx.request.header('Access-Control-Request-Method');
|
|
258
|
-
/**
|
|
259
|
-
* End the request, when `Access-Control-Request-Method` is missing or isn't
|
|
260
|
-
* part of allowed methods.
|
|
261
|
-
* https://www.w3.org/TR/cors/#http-access-control-request-method
|
|
262
|
-
*/
|
|
263
|
-
if (!requestMethod || this.options.methods.indexOf(requestMethod) === -1) {
|
|
264
|
-
this.endPreFlight(ctx.response);
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
/**
|
|
268
|
-
* When `Access-Control-Request-Headers` header is missing or is empty, then
|
|
269
|
-
* we subsitute that with an empty list.
|
|
270
|
-
* https://www.w3.org/TR/cors/#http-access-control-request-headers
|
|
271
|
-
*/
|
|
272
|
-
let requestHeaders = ctx.request.header('Access-Control-Request-Headers');
|
|
273
|
-
if (requestHeaders && requestHeaders !== '') {
|
|
274
|
-
requestHeaders = requestHeaders.split(',');
|
|
275
|
-
}
|
|
276
|
-
else {
|
|
277
|
-
requestHeaders = [];
|
|
278
|
-
}
|
|
279
|
-
/**
|
|
280
|
-
* Computing allowed headers array from the user config
|
|
281
|
-
*/
|
|
282
|
-
const allowedHeaders = this.computedAllowedHeaders(requestHeaders, ctx);
|
|
283
|
-
/**
|
|
284
|
-
* Finding if all request `Access-Control-Request-Headers` falls under the
|
|
285
|
-
* list of allowed headers inside user config
|
|
286
|
-
*/
|
|
287
|
-
const headersMatches = requestHeaders.every((header) => {
|
|
288
|
-
if (header === 'origin') {
|
|
289
|
-
return true;
|
|
290
|
-
}
|
|
291
|
-
/**
|
|
292
|
-
* Doing case insenstive match
|
|
293
|
-
*/
|
|
294
|
-
return allowedHeaders.indexOf(header.toLowerCase()) > -1;
|
|
295
|
-
});
|
|
296
|
-
/**
|
|
297
|
-
* If headers test fails, then we need to end the request without setting
|
|
298
|
-
* any headers (part of spec).
|
|
299
|
-
* https://www.w3.org/TR/cors/#http-access-control-request-headers
|
|
300
|
-
*/
|
|
301
|
-
if (headersMatches === false) {
|
|
302
|
-
this.endPreFlight(ctx.response);
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
this.setOrigin(ctx.response, allowedOrigin);
|
|
306
|
-
this.setCredentials(ctx.response);
|
|
307
|
-
this.setExposedHeaders(ctx.response);
|
|
308
|
-
this.setAllowMethods(ctx.response);
|
|
309
|
-
this.setAllowHeaders(ctx.response, allowedHeaders);
|
|
310
|
-
this.setMaxAge(ctx.response);
|
|
311
|
-
this.endPreFlight(ctx.response);
|
|
312
|
-
}
|
|
313
|
-
}
|
|
314
|
-
exports.Cors = Cors;
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
/// <reference types="@adonisjs/http-server/build/adonis-typings" />
|
|
2
|
-
import { AssetsConfig } from '@ioc:Adonis/Core/Static';
|
|
3
|
-
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
|
4
|
-
/**
|
|
5
|
-
* A simple server hook to serve static files from the public directory.
|
|
6
|
-
* The public directory must be configured within the `.adonisrc.json`
|
|
7
|
-
* file.
|
|
8
|
-
*/
|
|
9
|
-
export declare class ServeStatic {
|
|
10
|
-
private publicPath;
|
|
11
|
-
private config;
|
|
12
|
-
private serve;
|
|
13
|
-
constructor(publicPath: string, config: AssetsConfig);
|
|
14
|
-
/**
|
|
15
|
-
* Handle the request to serve static files.
|
|
16
|
-
*/
|
|
17
|
-
handle({ request, response }: HttpContextContract): Promise<void>;
|
|
18
|
-
}
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/core
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
11
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
12
|
-
};
|
|
13
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
-
exports.ServeStatic = void 0;
|
|
15
|
-
const serve_static_1 = __importDefault(require("serve-static"));
|
|
16
|
-
/**
|
|
17
|
-
* A simple server hook to serve static files from the public directory.
|
|
18
|
-
* The public directory must be configured within the `.adonisrc.json`
|
|
19
|
-
* file.
|
|
20
|
-
*/
|
|
21
|
-
class ServeStatic {
|
|
22
|
-
constructor(publicPath, config) {
|
|
23
|
-
this.publicPath = publicPath;
|
|
24
|
-
this.config = config;
|
|
25
|
-
this.serve = (0, serve_static_1.default)(this.publicPath, Object.assign({}, this.config, {
|
|
26
|
-
setHeaders: (res, path, stats) => {
|
|
27
|
-
const headers = res.parent.getHeaders();
|
|
28
|
-
Object.keys(headers).forEach((key) => {
|
|
29
|
-
res.setHeader(key, headers[key]);
|
|
30
|
-
});
|
|
31
|
-
/**
|
|
32
|
-
* Set user defined custom headers
|
|
33
|
-
*/
|
|
34
|
-
if (typeof this.config.headers === 'function') {
|
|
35
|
-
const customHeaders = this.config.headers(path, stats);
|
|
36
|
-
Object.keys(customHeaders).forEach((key) => {
|
|
37
|
-
res.setHeader(key, customHeaders[key]);
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
|
-
},
|
|
41
|
-
}));
|
|
42
|
-
}
|
|
43
|
-
/**
|
|
44
|
-
* Handle the request to serve static files.
|
|
45
|
-
*/
|
|
46
|
-
async handle({ request, response }) {
|
|
47
|
-
return new Promise((resolve) => {
|
|
48
|
-
function next() {
|
|
49
|
-
response.response.removeListener('finish', next);
|
|
50
|
-
resolve();
|
|
51
|
-
}
|
|
52
|
-
response.response['parent'] = response;
|
|
53
|
-
/**
|
|
54
|
-
* Whether or not the file has been served by serve static, we
|
|
55
|
-
* will cleanup the finish event listener.
|
|
56
|
-
*
|
|
57
|
-
* 1. If file has been served, then the `finish` callback get invoked.
|
|
58
|
-
* 2. If file has not been served, then callback (3rd argument) will
|
|
59
|
-
* get invoked.
|
|
60
|
-
*/
|
|
61
|
-
response.response.addListener('finish', next);
|
|
62
|
-
this.serve(request.request, response.response, next);
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
exports.ServeStatic = ServeStatic;
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
/// <reference types="@adonisjs/logger/build/adonis-typings/logger" />
|
|
2
|
-
/// <reference types="@adonisjs/http-server/build/adonis-typings" />
|
|
3
|
-
import { LoggerContract } from '@ioc:Adonis/Core/Logger';
|
|
4
|
-
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext';
|
|
5
|
-
/**
|
|
6
|
-
* Http exception handler serves as the base exception handler
|
|
7
|
-
* to handle all exceptions occured during the HTTP request
|
|
8
|
-
* lifecycle and makes appropriate response for them.
|
|
9
|
-
*/
|
|
10
|
-
export declare abstract class HttpExceptionHandler {
|
|
11
|
-
protected logger: LoggerContract;
|
|
12
|
-
/**
|
|
13
|
-
* An array of error codes that must not be reported
|
|
14
|
-
*/
|
|
15
|
-
protected ignoreCodes: string[];
|
|
16
|
-
/**
|
|
17
|
-
* An array of http statuses that must not be reported. The first
|
|
18
|
-
* level of filteration is on the basis of statuses and then
|
|
19
|
-
* the error codes.
|
|
20
|
-
*/
|
|
21
|
-
protected ignoreStatuses: number[];
|
|
22
|
-
/**
|
|
23
|
-
* An array of internal error codes to ignore
|
|
24
|
-
* from the reporting list
|
|
25
|
-
*/
|
|
26
|
-
protected internalIgnoreCodes: string[];
|
|
27
|
-
/**
|
|
28
|
-
* Map of status pages to render, instead of making the
|
|
29
|
-
* regular response
|
|
30
|
-
*/
|
|
31
|
-
protected statusPages: {
|
|
32
|
-
[key: string]: string;
|
|
33
|
-
};
|
|
34
|
-
/**
|
|
35
|
-
* Map of status pages for after expanding the expressions
|
|
36
|
-
* defined inside statusPages.
|
|
37
|
-
*
|
|
38
|
-
* This property is initialized using the getter defined at
|
|
39
|
-
* the end of this file
|
|
40
|
-
*/
|
|
41
|
-
expandedStatusPages: {
|
|
42
|
-
[key: string]: string;
|
|
43
|
-
};
|
|
44
|
-
/**
|
|
45
|
-
* A flag to disable status pages during development
|
|
46
|
-
*/
|
|
47
|
-
protected disableStatusPagesInDevelopment: boolean;
|
|
48
|
-
constructor(logger: LoggerContract);
|
|
49
|
-
/**
|
|
50
|
-
* A custom context to send to the logger when reporting
|
|
51
|
-
* errors.
|
|
52
|
-
*/
|
|
53
|
-
protected context(ctx: HttpContextContract): any;
|
|
54
|
-
/**
|
|
55
|
-
* Returns a boolean telling if a given error is supposed
|
|
56
|
-
* to be logged or not
|
|
57
|
-
*/
|
|
58
|
-
protected shouldReport(error: any): boolean;
|
|
59
|
-
/**
|
|
60
|
-
* Makes the JSON response, based upon the environment in
|
|
61
|
-
* which the app is runing
|
|
62
|
-
*/
|
|
63
|
-
protected makeJSONResponse(error: any, ctx: HttpContextContract): Promise<void>;
|
|
64
|
-
/**
|
|
65
|
-
* Makes the JSON API response, based upon the environment in
|
|
66
|
-
* which the app is runing
|
|
67
|
-
*/
|
|
68
|
-
protected makeJSONAPIResponse(error: any, ctx: HttpContextContract): Promise<void>;
|
|
69
|
-
/**
|
|
70
|
-
* Makes the HTML response, based upon the environment in
|
|
71
|
-
* which the app is runing
|
|
72
|
-
*/
|
|
73
|
-
protected makeHtmlResponse(error: any, ctx: HttpContextContract): Promise<void>;
|
|
74
|
-
/**
|
|
75
|
-
* Report a given error
|
|
76
|
-
*/
|
|
77
|
-
report(error: any, ctx: HttpContextContract): void;
|
|
78
|
-
/**
|
|
79
|
-
* Handle exception and make response
|
|
80
|
-
*/
|
|
81
|
-
handle(error: any, ctx: HttpContextContract): Promise<any>;
|
|
82
|
-
}
|
|
@@ -1,213 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* @adonisjs/core
|
|
4
|
-
*
|
|
5
|
-
* (c) Harminder Virk <virk@adonisjs.com>
|
|
6
|
-
*
|
|
7
|
-
* For the full copyright and license information, please view the LICENSE
|
|
8
|
-
* file that was distributed with this source code.
|
|
9
|
-
*/
|
|
10
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
11
|
-
exports.HttpExceptionHandler = void 0;
|
|
12
|
-
/**
|
|
13
|
-
* Http exception handler serves as the base exception handler
|
|
14
|
-
* to handle all exceptions occured during the HTTP request
|
|
15
|
-
* lifecycle and makes appropriate response for them.
|
|
16
|
-
*/
|
|
17
|
-
class HttpExceptionHandler {
|
|
18
|
-
constructor(logger) {
|
|
19
|
-
this.logger = logger;
|
|
20
|
-
/**
|
|
21
|
-
* An array of error codes that must not be reported
|
|
22
|
-
*/
|
|
23
|
-
this.ignoreCodes = [];
|
|
24
|
-
/**
|
|
25
|
-
* An array of http statuses that must not be reported. The first
|
|
26
|
-
* level of filteration is on the basis of statuses and then
|
|
27
|
-
* the error codes.
|
|
28
|
-
*/
|
|
29
|
-
this.ignoreStatuses = [400, 422, 401];
|
|
30
|
-
/**
|
|
31
|
-
* An array of internal error codes to ignore
|
|
32
|
-
* from the reporting list
|
|
33
|
-
*/
|
|
34
|
-
this.internalIgnoreCodes = ['E_ROUTE_NOT_FOUND'];
|
|
35
|
-
/**
|
|
36
|
-
* Map of status pages to render, instead of making the
|
|
37
|
-
* regular response
|
|
38
|
-
*/
|
|
39
|
-
this.statusPages = {};
|
|
40
|
-
/**
|
|
41
|
-
* A flag to disable status pages during development
|
|
42
|
-
*/
|
|
43
|
-
this.disableStatusPagesInDevelopment = true;
|
|
44
|
-
}
|
|
45
|
-
/**
|
|
46
|
-
* A custom context to send to the logger when reporting
|
|
47
|
-
* errors.
|
|
48
|
-
*/
|
|
49
|
-
context(ctx) {
|
|
50
|
-
const requestId = ctx.request.id();
|
|
51
|
-
return requestId
|
|
52
|
-
? {
|
|
53
|
-
'x-request-id': requestId,
|
|
54
|
-
}
|
|
55
|
-
: {};
|
|
56
|
-
}
|
|
57
|
-
/**
|
|
58
|
-
* Returns a boolean telling if a given error is supposed
|
|
59
|
-
* to be logged or not
|
|
60
|
-
*/
|
|
61
|
-
shouldReport(error) {
|
|
62
|
-
/**
|
|
63
|
-
* Do not report the error when it's status is mentioned inside
|
|
64
|
-
* the `ignoreStatuses` array.
|
|
65
|
-
*/
|
|
66
|
-
if (error.status && this.ignoreStatuses.indexOf(error.status) > -1) {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
/**
|
|
70
|
-
* Don't report when error has a code and it's in the ignore list.
|
|
71
|
-
*/
|
|
72
|
-
if (error.code && this.ignoreCodes.concat(this.internalIgnoreCodes).indexOf(error.code) > -1) {
|
|
73
|
-
return false;
|
|
74
|
-
}
|
|
75
|
-
return true;
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
|
-
* Makes the JSON response, based upon the environment in
|
|
79
|
-
* which the app is runing
|
|
80
|
-
*/
|
|
81
|
-
async makeJSONResponse(error, ctx) {
|
|
82
|
-
if (process.env.NODE_ENV === 'development') {
|
|
83
|
-
ctx.response.status(error.status).send({
|
|
84
|
-
message: error.message,
|
|
85
|
-
stack: error.stack,
|
|
86
|
-
code: error.code,
|
|
87
|
-
});
|
|
88
|
-
return;
|
|
89
|
-
}
|
|
90
|
-
ctx.response.status(error.status).send({ message: error.message });
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Makes the JSON API response, based upon the environment in
|
|
94
|
-
* which the app is runing
|
|
95
|
-
*/
|
|
96
|
-
async makeJSONAPIResponse(error, ctx) {
|
|
97
|
-
ctx.response.status(error.status).send({
|
|
98
|
-
errors: [
|
|
99
|
-
{
|
|
100
|
-
title: error.message,
|
|
101
|
-
...(process.env.NODE_ENV === 'development' ? { detail: error.stack } : {}),
|
|
102
|
-
code: error.code,
|
|
103
|
-
status: error.status,
|
|
104
|
-
},
|
|
105
|
-
],
|
|
106
|
-
});
|
|
107
|
-
}
|
|
108
|
-
/**
|
|
109
|
-
* Makes the HTML response, based upon the environment in
|
|
110
|
-
* which the app is runing
|
|
111
|
-
*/
|
|
112
|
-
async makeHtmlResponse(error, ctx) {
|
|
113
|
-
if (process.env.NODE_ENV === 'development' &&
|
|
114
|
-
(!this.expandedStatusPages[error.status] || this.disableStatusPagesInDevelopment)) {
|
|
115
|
-
const Youch = require('youch');
|
|
116
|
-
const html = await new Youch(error, ctx.request.request).toHTML();
|
|
117
|
-
ctx.response.status(error.status).send(html);
|
|
118
|
-
return;
|
|
119
|
-
}
|
|
120
|
-
/**
|
|
121
|
-
* Render status pages
|
|
122
|
-
*/
|
|
123
|
-
if (ctx['view'] && this.expandedStatusPages[error.status]) {
|
|
124
|
-
const html = await ctx['view'].render(this.expandedStatusPages[error.status], { error });
|
|
125
|
-
ctx.response.status(error.status).send(html);
|
|
126
|
-
return;
|
|
127
|
-
}
|
|
128
|
-
ctx.response.status(error.status).send(`<h1> ${error.message} </h1>`);
|
|
129
|
-
}
|
|
130
|
-
/**
|
|
131
|
-
* Report a given error
|
|
132
|
-
*/
|
|
133
|
-
report(error, ctx) {
|
|
134
|
-
error.status = error.status || 500;
|
|
135
|
-
if (!this.shouldReport(error)) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (typeof error.report === 'function') {
|
|
139
|
-
error.report(error, ctx);
|
|
140
|
-
return;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* - Using `error` for `500 and above`
|
|
144
|
-
* - `warn` for `400 and above`
|
|
145
|
-
* - `info` for rest. This should not happen, but technically it's possible for someone
|
|
146
|
-
* to raise with 200
|
|
147
|
-
*/
|
|
148
|
-
if (!error.status || error.status >= 500) {
|
|
149
|
-
if (process.env.NODE_ENV !== 'test') {
|
|
150
|
-
ctx.logger.error({ err: error, ...this.context(ctx) }, error.message);
|
|
151
|
-
}
|
|
152
|
-
}
|
|
153
|
-
else if (error.status >= 400) {
|
|
154
|
-
ctx.logger.warn(this.context(ctx), error.message);
|
|
155
|
-
}
|
|
156
|
-
else {
|
|
157
|
-
ctx.logger.info(this.context(ctx), error.message);
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
/**
|
|
161
|
-
* Handle exception and make response
|
|
162
|
-
*/
|
|
163
|
-
async handle(error, ctx) {
|
|
164
|
-
error.status = error.status || 500;
|
|
165
|
-
if (typeof error.handle === 'function') {
|
|
166
|
-
return error.handle(error, ctx);
|
|
167
|
-
}
|
|
168
|
-
/**
|
|
169
|
-
* Send stack in the response when in test environment and
|
|
170
|
-
* there is a fatal error.
|
|
171
|
-
*/
|
|
172
|
-
if (error.status >= 500 && error.stack && process.env.NODE_ENV === 'test') {
|
|
173
|
-
return ctx.response.status(error.status).send(error.stack);
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Attempt to find the best error reporter for validation
|
|
177
|
-
*/
|
|
178
|
-
switch (ctx.request.accepts(['html', 'application/vnd.api+json', 'json'])) {
|
|
179
|
-
case 'html':
|
|
180
|
-
case null:
|
|
181
|
-
return this.makeHtmlResponse(error, ctx);
|
|
182
|
-
case 'json':
|
|
183
|
-
return this.makeJSONResponse(error, ctx);
|
|
184
|
-
case 'application/vnd.api+json':
|
|
185
|
-
return this.makeJSONAPIResponse(error, ctx);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
exports.HttpExceptionHandler = HttpExceptionHandler;
|
|
190
|
-
/**
|
|
191
|
-
* Single getter to pull status pages after expanding the range expression
|
|
192
|
-
*/
|
|
193
|
-
Object.defineProperty(HttpExceptionHandler.prototype, 'expandedStatusPages', {
|
|
194
|
-
get() {
|
|
195
|
-
const value = Object.keys(this.statusPages).reduce((result, codeRange) => {
|
|
196
|
-
const parts = codeRange.split('.');
|
|
197
|
-
const min = Number(parts[0]);
|
|
198
|
-
const max = Number(parts[parts.length - 1]);
|
|
199
|
-
if (isNaN(min) || isNaN(max)) {
|
|
200
|
-
return result;
|
|
201
|
-
}
|
|
202
|
-
if (min === max) {
|
|
203
|
-
result[codeRange] = this.statusPages[codeRange];
|
|
204
|
-
}
|
|
205
|
-
Array.apply(null, new Array(max - min + 1)).forEach((_, step) => {
|
|
206
|
-
result[min + step] = this.statusPages[codeRange];
|
|
207
|
-
});
|
|
208
|
-
return result;
|
|
209
|
-
}, {});
|
|
210
|
-
Object.defineProperty(this, 'expandedStatusPages', { value });
|
|
211
|
-
return value;
|
|
212
|
-
},
|
|
213
|
-
});
|