mythix 2.4.3 → 2.4.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mythix",
3
- "version": "2.4.3",
3
+ "version": "2.4.7",
4
4
  "description": "Mythix is a NodeJS web-app framework",
5
5
  "main": "src/index.js",
6
6
  "scripts": {
@@ -30,7 +30,7 @@
30
30
  "express": "^4.17.3",
31
31
  "express-busboy": "github:th317erd/express-busboy#0754a570d7979097b31e48655b80d3fcd628d4e4",
32
32
  "form-data": "^4.0.0",
33
- "mythix-orm": "^1.4.7",
33
+ "mythix-orm": "^1.5.1",
34
34
  "nife": "^1.11.3",
35
35
  "prompts": "^2.4.2"
36
36
  }
@@ -307,6 +307,8 @@ function loadMythixConfig(_mythixConfigPath, _appRootPath) {
307
307
  let appRootPath = (_appRootPath) ? Path.resolve(_appRootPath) : Path.resolve(mythixConfigPath, 'app');
308
308
 
309
309
  let defaultConfig = {
310
+ runtime: process.env.MYTHIX_RUNTIME || 'node',
311
+ runtimeArgs: (process.env.MYTHIX_RUNTIME_ARGS || '').split(/\s+/g),
310
312
  applicationPath: (config) => Path.resolve(config.appRootPath, 'application.js'),
311
313
  getApplicationClass: (config) => {
312
314
  let Application = require(config.applicationPath);
@@ -337,14 +339,15 @@ function loadMythixConfig(_mythixConfigPath, _appRootPath) {
337
339
  return resolveConfig(defaultConfig);
338
340
  }
339
341
 
340
- function spawnCommand(args, options) {
342
+ function spawnCommand(args, options, _config) {
343
+ const config = _config || {};
341
344
  const { spawn } = require('child_process');
342
345
 
343
346
  return new Promise((resolve, reject) => {
344
347
  try {
345
348
  let childProcess = spawn(
346
- 'node',
347
- args,
349
+ config.runtime || 'node',
350
+ (config.runtimeArgs || []).concat(args),
348
351
  Object.assign({}, options || {}, {
349
352
  env: Object.assign({}, process.env, (options || {}).env || {}),
350
353
  stdio: 'inherit',
@@ -364,16 +367,17 @@ function spawnCommand(args, options) {
364
367
  });
365
368
  }
366
369
 
367
- async function executeCommand(configPath, applicationCommandsPath, yargsPath, simpleYargsPath, argv, commandPath, command) {
370
+ async function executeCommand(configPath, applicationCommandsPath, yargsPath, simpleYargsPath, argv, commandPath, command, config) {
368
371
  try {
369
372
  let Klass = CommandBase.commands[command];
370
- let nodeArguments = Klass.nodeArguments || [];
373
+ let nodeArguments = ((config.runtime || 'node') === 'node') ? (Klass.nodeArguments || []) : [];
371
374
  let args = nodeArguments.concat([ commandPath ], argv);
372
375
 
373
376
  let code = await spawnCommand(
374
377
  args,
375
378
  {
376
379
  env: {
380
+ MYTHIX_RUNTIME: config.runtime || process.env.MYTHIX_RUNTIME || 'node',
377
381
  MYTHIX_CONFIG_PATH: configPath,
378
382
  MYTHIX_COMMAND_PATH: commandPath,
379
383
  MYTHIX_APPLICATION_COMMANDS: applicationCommandsPath,
@@ -382,6 +386,7 @@ async function executeCommand(configPath, applicationCommandsPath, yargsPath, si
382
386
  MYTHIX_EXECUTE_COMMAND: command,
383
387
  },
384
388
  },
389
+ config,
385
390
  );
386
391
 
387
392
  process.exit(code);
@@ -183,13 +183,13 @@ class ControllerBase {
183
183
  this.responseStatusCode = parseInt(code, 10);
184
184
  }
185
185
 
186
- async handleIncomingRequest(request, response, { route, controllerMethod, startTime, params, query /* , controller, controllerInstance, */ }) {
187
- this.route = route;
186
+ async handleIncomingRequest(request, response, args) {
187
+ this.route = args.route;
188
188
 
189
- if (typeof this[controllerMethod] !== 'function')
190
- this.throwInternalServerError(`Specified route handler named "${this.constructor.name}::${controllerMethod}" not found.`);
189
+ if (typeof this[args.controllerMethod] !== 'function')
190
+ this.throwInternalServerError(`Specified route handler named "${this.constructor.name}::${args.controllerMethod}" not found.`);
191
191
 
192
- return await this[controllerMethod].call(this, { params, query, body: request.body, request, response, startTime }, this.getModels());
192
+ return await this[args.controllerMethod].call(this, { body: request.body, request, response, ...args }, this.getModels());
193
193
  }
194
194
 
195
195
  async handleOutgoingResponse(_controllerResult, request, response /*, { route, controller, controllerMethod, controllerInstance, startTime, params } */) {
@@ -239,15 +239,22 @@ class HTTPServer {
239
239
  }
240
240
 
241
241
  createRequestLogger(application, request) {
242
- if (request.mythixLogger)
242
+ let requestID = (Date.now() + Math.random()).toFixed(REQUEST_ID_POSTFIX_LENGTH);
243
+
244
+ if (request.mythixLogger) {
245
+ if (!request.mythixRequestID)
246
+ request.mythixRequestID = requestID;
247
+
243
248
  return request.mythixLogger;
249
+ }
244
250
 
245
251
  let logger = application.getLogger();
246
252
  let loggerMethod = ('' + request.method).toUpperCase();
247
253
  let loggerURL = ('' + request.path);
248
- let requestID = (Date.now() + Math.random()).toFixed(REQUEST_ID_POSTFIX_LENGTH);
249
254
  let ipAddress = Nife.get(request, 'client.remoteAddress', '<unknown IP address>');
250
255
 
256
+ request.mythixRequestID = requestID;
257
+
251
258
  return logger.clone({ formatter: (output) => `{${ipAddress}} - [#${requestID} ${loggerMethod} ${loggerURL}]: ${output}`});
252
259
  }
253
260