badmfck-api-server 4.0.52 → 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>;
@@ -95,11 +95,12 @@ async function Initializer(services) {
95
95
  }
96
96
  exports.Initializer = Initializer;
97
97
  class APIService extends BaseService_1.BaseService {
98
- version = "4.0.5";
98
+ version = "4.0.6";
99
99
  options;
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,6 +239,8 @@ class APIService extends BaseService_1.BaseService {
234
239
  const originHeader = req.headers.origin;
235
240
  if (!originHeader)
236
241
  return next();
242
+ if (this.noCors)
243
+ return next();
237
244
  let originNorm;
238
245
  try {
239
246
  originNorm = new URL(String(originHeader)).origin.replace(/\/$/, "");
@@ -243,6 +250,7 @@ class APIService extends BaseService_1.BaseService {
243
250
  error: { ...DefaultErrors_1.default.FORBIDDEN, details: "Invalid Origin header" },
244
251
  data: null,
245
252
  httpStatus: 403,
253
+ version: this.options.appVersion
246
254
  });
247
255
  return;
248
256
  }
@@ -251,6 +259,7 @@ class APIService extends BaseService_1.BaseService {
251
259
  error: { ...DefaultErrors_1.default.FORBIDDEN, details: `Origin not allowed: ${originNorm}` },
252
260
  data: null,
253
261
  httpStatus: 403,
262
+ version: this.options.appVersion
254
263
  });
255
264
  return;
256
265
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "badmfck-api-server",
3
- "version": "4.0.52",
3
+ "version": "4.0.62",
4
4
  "description": "Simple API http server based on express",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",