@webtypen/webframez-core 0.0.18 → 0.0.19

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.
@@ -13,6 +13,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
13
13
  };
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Router = void 0;
16
+ const fs_1 = __importDefault(require("fs"));
16
17
  const qs_1 = __importDefault(require("qs"));
17
18
  const Response_1 = require("./Response");
18
19
  const Config_1 = require("../Config");
@@ -270,7 +271,7 @@ class RouterFacade {
270
271
  }
271
272
  // Set Controller method as route-component
272
273
  const controllerInstance = new controller();
273
- route.component = controllerInstance[split[1]];
274
+ route.component = controllerInstance[split[1]].bind(controllerInstance);
274
275
  }
275
276
  if (route && route.component !== undefined) {
276
277
  try {
@@ -291,7 +292,8 @@ class RouterFacade {
291
292
  });
292
293
  }
293
294
  requestConsoleLog(req, httpCode) {
294
- if (Config_1.Config.get("application.router.requests.logConsole") !== true) {
295
+ if (Config_1.Config.get("application.router.requests.logConsole") !== true &&
296
+ !Config_1.Config.get("application.router.requests.logFile")) {
295
297
  return;
296
298
  }
297
299
  const date = new Date();
@@ -305,7 +307,7 @@ class RouterFacade {
305
307
  : req.socket && req.socket.remoteAddress
306
308
  ? req.socket.remoteAddress
307
309
  : null;
308
- console.log('{ date: "' +
310
+ const logString = '{ date: "' +
309
311
  date.getFullYear() +
310
312
  "-" +
311
313
  (month < 10 ? "0" + month : month) +
@@ -325,7 +327,23 @@ class RouterFacade {
325
327
  ip +
326
328
  '", httpcode: ' +
327
329
  httpCode.toString() +
328
- " }");
330
+ " }";
331
+ if (Config_1.Config.get("application.router.requests.logConsole")) {
332
+ console.log(logString);
333
+ }
334
+ if (Config_1.Config.get("application.router.requests.logFile")) {
335
+ try {
336
+ const filepath = Config_1.Config.get("application.router.requests.logFile");
337
+ if (filepath && filepath.trim() !== "") {
338
+ fs_1.default.appendFileSync(filepath.trim().substring(0, 1) === "/"
339
+ ? filepath
340
+ : process.cwd() + "/" + filepath, logString + "\n");
341
+ }
342
+ }
343
+ catch (e) {
344
+ console.error(e);
345
+ }
346
+ }
329
347
  }
330
348
  }
331
349
  exports.Router = new RouterFacade();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webtypen/webframez-core",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "description": "The core package of the typescript based webframez (web-framework) by webtypen.de",
5
5
  "homepage": "https://webtypen.de/",
6
6
  "license": "MIT",
@@ -1,3 +1,4 @@
1
+ import fs from "fs";
1
2
  import qs from "qs";
2
3
  import { IncomingMessage, ServerResponse } from "http";
3
4
  import { Response } from "./Response";
@@ -328,7 +329,7 @@ class RouterFacade {
328
329
 
329
330
  // Set Controller method as route-component
330
331
  const controllerInstance = new controller();
331
- route.component = controllerInstance[split[1]];
332
+ route.component = controllerInstance[split[1]].bind(controllerInstance);
332
333
  }
333
334
 
334
335
  if (route && route.component !== undefined) {
@@ -348,7 +349,10 @@ class RouterFacade {
348
349
  }
349
350
 
350
351
  requestConsoleLog(req: IncomingMessage, httpCode: number) {
351
- if (Config.get("application.router.requests.logConsole") !== true) {
352
+ if (
353
+ Config.get("application.router.requests.logConsole") !== true &&
354
+ !Config.get("application.router.requests.logFile")
355
+ ) {
352
356
  return;
353
357
  }
354
358
 
@@ -363,30 +367,48 @@ class RouterFacade {
363
367
  : req.socket && req.socket.remoteAddress
364
368
  ? req.socket.remoteAddress
365
369
  : null;
366
-
367
- console.log(
370
+ const logString =
368
371
  '{ date: "' +
369
- date.getFullYear() +
370
- "-" +
371
- (month < 10 ? "0" + month : month) +
372
- "-" +
373
- date.getDate() +
374
- " " +
375
- (date.getHours() + 1) +
376
- ":" +
377
- date.getMinutes() +
378
- ":" +
379
- date.getSeconds() +
380
- '", method: "' +
381
- req.method +
382
- '", url: "' +
383
- req.url +
384
- '", ip: "' +
385
- ip +
386
- '", httpcode: ' +
387
- httpCode.toString() +
388
- " }"
389
- );
372
+ date.getFullYear() +
373
+ "-" +
374
+ (month < 10 ? "0" + month : month) +
375
+ "-" +
376
+ date.getDate() +
377
+ " " +
378
+ (date.getHours() + 1) +
379
+ ":" +
380
+ date.getMinutes() +
381
+ ":" +
382
+ date.getSeconds() +
383
+ '", method: "' +
384
+ req.method +
385
+ '", url: "' +
386
+ req.url +
387
+ '", ip: "' +
388
+ ip +
389
+ '", httpcode: ' +
390
+ httpCode.toString() +
391
+ " }";
392
+
393
+ if (Config.get("application.router.requests.logConsole")) {
394
+ console.log(logString);
395
+ }
396
+
397
+ if (Config.get("application.router.requests.logFile")) {
398
+ try {
399
+ const filepath = Config.get("application.router.requests.logFile");
400
+ if (filepath && filepath.trim() !== "") {
401
+ fs.appendFileSync(
402
+ filepath.trim().substring(0, 1) === "/"
403
+ ? filepath
404
+ : process.cwd() + "/" + filepath,
405
+ logString + "\n"
406
+ );
407
+ }
408
+ } catch (e) {
409
+ console.error(e);
410
+ }
411
+ }
390
412
  }
391
413
  }
392
414