@tstdl/base 0.71.25 → 0.71.26
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.
|
@@ -4,21 +4,16 @@ exports.corsMiddleware = void 0;
|
|
|
4
4
|
const type_guards_1 = require("../../../utils/type-guards");
|
|
5
5
|
// eslint-disable-next-line max-statements
|
|
6
6
|
async function corsMiddleware(request, next, context) {
|
|
7
|
-
var _a;
|
|
7
|
+
var _a, _b;
|
|
8
8
|
const response = await next(request);
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
if (corses.length == 0) {
|
|
9
|
+
const requestMethod = request.headers.tryGetSingle('Access-Control-Request-Method');
|
|
10
|
+
const cors = (_a = context.api.endpoints.get(requestMethod)) === null || _a === void 0 ? void 0 : _a.definition.cors;
|
|
11
|
+
if ((0, type_guards_1.isUndefined)(cors)) {
|
|
13
12
|
return response;
|
|
14
13
|
}
|
|
15
|
-
if (corses.length > 1) {
|
|
16
|
-
throw new Error('cors can only be defined once per resource');
|
|
17
|
-
}
|
|
18
|
-
const cors = corses[0];
|
|
19
14
|
if (request.method == 'OPTIONS') {
|
|
20
15
|
const allowMethods = [...context.api.endpoints.keys()].join(', ');
|
|
21
|
-
response.headers.setIfMissing('Access-Control-Allow-Methods', (
|
|
16
|
+
response.headers.setIfMissing('Access-Control-Allow-Methods', (_b = cors.accessControlAllowMethods) !== null && _b !== void 0 ? _b : allowMethods);
|
|
22
17
|
if (cors.accessControlAllowCredentials == true) {
|
|
23
18
|
response.headers.setIfMissing('Access-Control-Allow-Credentials', 'true');
|
|
24
19
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cors.middleware.js","sourceRoot":"","sources":["../../../../source/api/server/middlewares/cors.middleware.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"cors.middleware.js","sourceRoot":"","sources":["../../../../source/api/server/middlewares/cors.middleware.ts"],"names":[],"mappings":";;;AAGA,4D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