badmfck-api-server 4.0.61 → 4.0.62
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.
|
@@ -65,6 +65,7 @@ export declare class APIService<TInterceptorResult = any, TInternalCallParams =
|
|
|
65
65
|
private monitor;
|
|
66
66
|
private started;
|
|
67
67
|
private requestsCount;
|
|
68
|
+
private noCors;
|
|
68
69
|
netLog: APIServiceNetworkLogItem[];
|
|
69
70
|
constructor(options: APIServiceOptions);
|
|
70
71
|
init(): Promise<void>;
|
|
@@ -100,6 +100,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
100
100
|
monitor = null;
|
|
101
101
|
started = new Date();
|
|
102
102
|
requestsCount = 0;
|
|
103
|
+
noCors = false;
|
|
103
104
|
netLog = [];
|
|
104
105
|
constructor(options) {
|
|
105
106
|
super('HTTP Service');
|
|
@@ -109,6 +110,10 @@ class APIService extends BaseService_1.BaseService {
|
|
|
109
110
|
const self = "http://localhost:" + this.options.port;
|
|
110
111
|
if (!this.options.corsHostWhiteList.find(val => val === self))
|
|
111
112
|
this.options.corsHostWhiteList.push(self);
|
|
113
|
+
if (this.options.corsHostWhiteList.length === 0)
|
|
114
|
+
this.noCors = true;
|
|
115
|
+
if (this.options.corsHostWhiteList.find(x => x === "*"))
|
|
116
|
+
this.noCors = true;
|
|
112
117
|
const list = [];
|
|
113
118
|
for (let h of this.options.corsHostWhiteList) {
|
|
114
119
|
h = h.replace(/\/$/, "");
|
|
@@ -234,7 +239,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
234
239
|
const originHeader = req.headers.origin;
|
|
235
240
|
if (!originHeader)
|
|
236
241
|
return next();
|
|
237
|
-
if (this.
|
|
242
|
+
if (this.noCors)
|
|
238
243
|
return next();
|
|
239
244
|
let originNorm;
|
|
240
245
|
try {
|
|
@@ -245,6 +250,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
245
250
|
error: { ...DefaultErrors_1.default.FORBIDDEN, details: "Invalid Origin header" },
|
|
246
251
|
data: null,
|
|
247
252
|
httpStatus: 403,
|
|
253
|
+
version: this.options.appVersion
|
|
248
254
|
});
|
|
249
255
|
return;
|
|
250
256
|
}
|
|
@@ -253,6 +259,7 @@ class APIService extends BaseService_1.BaseService {
|
|
|
253
259
|
error: { ...DefaultErrors_1.default.FORBIDDEN, details: `Origin not allowed: ${originNorm}` },
|
|
254
260
|
data: null,
|
|
255
261
|
httpStatus: 403,
|
|
262
|
+
version: this.options.appVersion
|
|
256
263
|
});
|
|
257
264
|
return;
|
|
258
265
|
}
|