opticore-webapp 1.0.89 → 1.0.91

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/dist/index.cjs CHANGED
@@ -31,7 +31,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
31
31
  var index_exports = {};
32
32
  __export(index_exports, {
33
33
  WebServer: () => WebServerCore,
34
- envPath: () => envPath
34
+ envPath: () => envPath,
35
+ expressErrorHandler: () => expressErrorHandler
35
36
  });
36
37
  module.exports = __toCommonJS(index_exports);
37
38
 
@@ -40,7 +41,7 @@ var path3 = __toESM(require("path"), 1);
40
41
  var import_node_process4 = __toESM(require("process"), 1);
41
42
  var import_cors = __toESM(require("cors"), 1);
42
43
  var import_opticore_catch_exception_error3 = require("opticore-catch-exception-error");
43
- var import_opticore_express2 = require("opticore-express");
44
+ var import_opticore_express = require("opticore-express");
44
45
  var import_opticore_env_access2 = require("opticore-env-access");
45
46
  var import_opticore_http_response4 = require("opticore-http-response");
46
47
  var import_opticore_translator3 = require("opticore-translator");
@@ -50,15 +51,9 @@ var import_opticore_watcher = require("opticore-watcher");
50
51
  // src/core/handlers/eventProcess.handler.ts
51
52
  var import_node_process = __toESM(require("process"), 1);
52
53
  var import_node_events = __toESM(require("events"), 1);
53
- var import_opticore_express = require("opticore-express");
54
54
  var import_opticore_catch_exception_error = require("opticore-catch-exception-error");
55
55
  function eventProcessHandler(localeLanguage) {
56
- const errorEmitter = new import_node_events.default();
57
- const app = (0, import_opticore_express.express)();
58
56
  const serverListenEvent = new import_opticore_catch_exception_error.ServerListenEventError(localeLanguage);
59
- errorEmitter.on(import_opticore_catch_exception_error.CEventNameError.error, (error) => {
60
- serverListenEvent.listenerError(error);
61
- });
62
57
  import_node_process.default.on(import_opticore_catch_exception_error.CEvent.beforeExit, (code) => {
63
58
  setTimeout(() => {
64
59
  serverListenEvent.processBeforeExit(code);
@@ -97,9 +92,16 @@ function eventProcessHandler(localeLanguage) {
97
92
  import_node_process.default.on(import_opticore_catch_exception_error.CEvent.sigterm, (signal) => {
98
93
  serverListenEvent.sigtermSignalReceived(signal);
99
94
  });
100
- app.use((err, req, res, next) => {
101
- serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
95
+ }
96
+ function expressErrorHandler(localeLanguage) {
97
+ const errorEmitter = new import_node_events.default();
98
+ const serverListenEvent = new import_opticore_catch_exception_error.ServerListenEventError(localeLanguage);
99
+ errorEmitter.on(import_opticore_catch_exception_error.CEventNameError.error, (error) => {
100
+ serverListenEvent.listenerError(error);
102
101
  });
102
+ return (err, req, res, next) => {
103
+ serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
104
+ };
103
105
  }
104
106
 
105
107
  // src/application/service/core.service.ts
@@ -519,7 +521,7 @@ function startHmrSupervisor(options) {
519
521
  // src/core/webServer.core.ts
520
522
  var WebServerCore = class {
521
523
  serverUtility;
522
- expressApp = (0, import_opticore_express2.express)();
524
+ expressApp = (0, import_opticore_express.express)();
523
525
  container;
524
526
  localLanguage;
525
527
  loggerConfig;
@@ -538,10 +540,10 @@ var WebServerCore = class {
538
540
  this.localLanguage = paramsConstructor.localLanguage;
539
541
  this.environmentPath = paramsConstructor.environmentPath;
540
542
  this.container = new import_opticore_dependency_inject2.SContainer(paramsConstructor.localLanguage);
541
- this.expressApp.use(import_opticore_express2.express.json());
542
- this.expressApp.use(import_opticore_express2.express.raw());
543
- this.expressApp.use(import_opticore_express2.express.text());
544
- this.expressApp.use(import_opticore_express2.express.urlencoded({ extended: true }));
543
+ this.expressApp.use(import_opticore_express.express.json());
544
+ this.expressApp.use(import_opticore_express.express.raw());
545
+ this.expressApp.use(import_opticore_express.express.text());
546
+ this.expressApp.use(import_opticore_express.express.urlencoded({ extended: true }));
545
547
  this.expressApp.use((0, import_cors.default)(paramsConstructor.corsOriginOptions));
546
548
  this.serverListenEvent = new import_opticore_catch_exception_error3.ServerListenEventError(paramsConstructor.localLanguage);
547
549
  this.serverUtility = new CoreService(paramsConstructor.localLanguage, paramsConstructor.environmentPath, this.container);
@@ -615,8 +617,9 @@ var WebServerCore = class {
615
617
  this.registerDependencies(dependenciesProvider);
616
618
  }
617
619
  this.container.loadServices();
618
- this.expressApp.use(import_opticore_express2.express.static(path3.join(import_node_process4.default.cwd(), "public/template")));
620
+ this.expressApp.use(import_opticore_express.express.static(path3.join(import_node_process4.default.cwd(), "public/template")));
619
621
  this.registerRoutes(routers);
622
+ this.expressApp.use(expressErrorHandler(this.localLanguage));
620
623
  const resolvedHmr = this.resolveHotReloadConfig();
621
624
  if (resolvedHmr !== null) {
622
625
  new import_opticore_watcher.HotReloadWatcher(resolvedHmr).attach(server);
@@ -771,5 +774,6 @@ var WebServerCore = class {
771
774
  // Annotate the CommonJS export names for ESM import in node:
772
775
  0 && (module.exports = {
773
776
  WebServer,
774
- envPath
777
+ envPath,
778
+ expressErrorHandler
775
779
  });
package/dist/index.d.cts CHANGED
@@ -2,7 +2,7 @@ import * as http from 'http';
2
2
  import { Server } from 'http';
3
3
  import { TFeatureRoutes } from 'opticore-router';
4
4
  import { TDependency } from 'opticore-dependency-inject';
5
- import { express } from 'opticore-express';
5
+ import { express, ErrorRequestHandler } from 'opticore-express';
6
6
  import { LoggerCore } from 'opticore-logger';
7
7
  import { CorsOptions } from 'cors';
8
8
  import { HotReloadConfig } from 'opticore-watcher';
@@ -124,6 +124,18 @@ declare class WebServerCore {
124
124
 
125
125
  declare const envPath: string;
126
126
 
127
+ /**
128
+ * Express error-handling middleware. It must be mounted on the application that actually serves requests,
129
+ * AFTER its routes: an error-handling middleware only receives the errors of the middleware registered before it.
130
+ *
131
+ * (It used to be mounted on a throw-away `express()` instance created inside eventProcessHandler, so it never ran
132
+ * and every unhandled error — a malformed JSON body, for instance — fell through to Express's default handler,
133
+ * which prints the stack trace and file paths outside production.)
134
+ *
135
+ * The client gets a fixed message; the error itself is logged.
136
+ */
137
+ declare function expressErrorHandler(localeLanguage: string): ErrorRequestHandler;
138
+
127
139
  type KernelModuleType = [any[], () => void];
128
140
 
129
- export { type KernelModuleType, WebServerCore as WebServer, envPath };
141
+ export { type KernelModuleType, WebServerCore as WebServer, envPath, expressErrorHandler };
package/dist/index.d.ts CHANGED
@@ -2,7 +2,7 @@ import * as http from 'http';
2
2
  import { Server } from 'http';
3
3
  import { TFeatureRoutes } from 'opticore-router';
4
4
  import { TDependency } from 'opticore-dependency-inject';
5
- import { express } from 'opticore-express';
5
+ import { express, ErrorRequestHandler } from 'opticore-express';
6
6
  import { LoggerCore } from 'opticore-logger';
7
7
  import { CorsOptions } from 'cors';
8
8
  import { HotReloadConfig } from 'opticore-watcher';
@@ -124,6 +124,18 @@ declare class WebServerCore {
124
124
 
125
125
  declare const envPath: string;
126
126
 
127
+ /**
128
+ * Express error-handling middleware. It must be mounted on the application that actually serves requests,
129
+ * AFTER its routes: an error-handling middleware only receives the errors of the middleware registered before it.
130
+ *
131
+ * (It used to be mounted on a throw-away `express()` instance created inside eventProcessHandler, so it never ran
132
+ * and every unhandled error — a malformed JSON body, for instance — fell through to Express's default handler,
133
+ * which prints the stack trace and file paths outside production.)
134
+ *
135
+ * The client gets a fixed message; the error itself is logged.
136
+ */
137
+ declare function expressErrorHandler(localeLanguage: string): ErrorRequestHandler;
138
+
127
139
  type KernelModuleType = [any[], () => void];
128
140
 
129
- export { type KernelModuleType, WebServerCore as WebServer, envPath };
141
+ export { type KernelModuleType, WebServerCore as WebServer, envPath, expressErrorHandler };
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import * as path3 from "path";
3
3
  import process6 from "process";
4
4
  import corsOrigin from "cors";
5
5
  import { CEventNameError as eventName2, ServerListenEventError as ServerListenEventError2 } from "opticore-catch-exception-error";
6
- import { express as express2 } from "opticore-express";
6
+ import { express } from "opticore-express";
7
7
  import { getEnvironmentValue as getEnvironmentValue2 } from "opticore-env-access";
8
8
  import { HttpStatusCode as HttpStatusCode3 } from "opticore-http-response";
9
9
  import { TranslationLoader as TranslationLoader3 } from "opticore-translator";
@@ -13,15 +13,9 @@ import { HotReloadWatcher } from "opticore-watcher";
13
13
  // src/core/handlers/eventProcess.handler.ts
14
14
  import process2 from "process";
15
15
  import EventEmitter from "events";
16
- import { express } from "opticore-express";
17
16
  import { ServerListenEventError, CEventNameError as eventName, CEvent as event } from "opticore-catch-exception-error";
18
17
  function eventProcessHandler(localeLanguage) {
19
- const errorEmitter = new EventEmitter();
20
- const app = express();
21
18
  const serverListenEvent = new ServerListenEventError(localeLanguage);
22
- errorEmitter.on(eventName.error, (error) => {
23
- serverListenEvent.listenerError(error);
24
- });
25
19
  process2.on(event.beforeExit, (code) => {
26
20
  setTimeout(() => {
27
21
  serverListenEvent.processBeforeExit(code);
@@ -60,9 +54,16 @@ function eventProcessHandler(localeLanguage) {
60
54
  process2.on(event.sigterm, (signal) => {
61
55
  serverListenEvent.sigtermSignalReceived(signal);
62
56
  });
63
- app.use((err, req, res, next) => {
64
- serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
57
+ }
58
+ function expressErrorHandler(localeLanguage) {
59
+ const errorEmitter = new EventEmitter();
60
+ const serverListenEvent = new ServerListenEventError(localeLanguage);
61
+ errorEmitter.on(eventName.error, (error) => {
62
+ serverListenEvent.listenerError(error);
65
63
  });
64
+ return (err, req, res, next) => {
65
+ serverListenEvent.expressErrorHandlingMiddleware(errorEmitter, err, req, res, next);
66
+ };
66
67
  }
67
68
 
68
69
  // src/application/service/core.service.ts
@@ -485,7 +486,7 @@ function startHmrSupervisor(options) {
485
486
  // src/core/webServer.core.ts
486
487
  var WebServerCore = class {
487
488
  serverUtility;
488
- expressApp = express2();
489
+ expressApp = express();
489
490
  container;
490
491
  localLanguage;
491
492
  loggerConfig;
@@ -504,10 +505,10 @@ var WebServerCore = class {
504
505
  this.localLanguage = paramsConstructor.localLanguage;
505
506
  this.environmentPath = paramsConstructor.environmentPath;
506
507
  this.container = new SContainer2(paramsConstructor.localLanguage);
507
- this.expressApp.use(express2.json());
508
- this.expressApp.use(express2.raw());
509
- this.expressApp.use(express2.text());
510
- this.expressApp.use(express2.urlencoded({ extended: true }));
508
+ this.expressApp.use(express.json());
509
+ this.expressApp.use(express.raw());
510
+ this.expressApp.use(express.text());
511
+ this.expressApp.use(express.urlencoded({ extended: true }));
511
512
  this.expressApp.use(corsOrigin(paramsConstructor.corsOriginOptions));
512
513
  this.serverListenEvent = new ServerListenEventError2(paramsConstructor.localLanguage);
513
514
  this.serverUtility = new CoreService(paramsConstructor.localLanguage, paramsConstructor.environmentPath, this.container);
@@ -581,8 +582,9 @@ var WebServerCore = class {
581
582
  this.registerDependencies(dependenciesProvider);
582
583
  }
583
584
  this.container.loadServices();
584
- this.expressApp.use(express2.static(path3.join(process6.cwd(), "public/template")));
585
+ this.expressApp.use(express.static(path3.join(process6.cwd(), "public/template")));
585
586
  this.registerRoutes(routers);
587
+ this.expressApp.use(expressErrorHandler(this.localLanguage));
586
588
  const resolvedHmr = this.resolveHotReloadConfig();
587
589
  if (resolvedHmr !== null) {
588
590
  new HotReloadWatcher(resolvedHmr).attach(server);
@@ -736,5 +738,6 @@ var WebServerCore = class {
736
738
  };
737
739
  export {
738
740
  WebServerCore as WebServer,
739
- envPath
741
+ envPath,
742
+ expressErrorHandler
740
743
  };
package/package.json CHANGED
@@ -1,13 +1,13 @@
1
1
  {
2
2
  "name": "opticore-webapp",
3
- "version": "1.0.89",
3
+ "version": "1.0.91",
4
4
  "description": "wep server",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",
7
7
  "types": "dist/index.d.ts",
8
8
  "type": "module",
9
9
  "scripts": {
10
- "test": "echo \"Error: no test specified\" && exit 1",
10
+ "test": "node --test test/*.test.mjs",
11
11
  "build": "tsup"
12
12
  },
13
13
  "files": [
@@ -32,18 +32,18 @@
32
32
  "chalk": "^5.6.2",
33
33
  "cors": "^2.8.6",
34
34
  "gradient-string": "^3.0.0",
35
- "opticore-catch-exception-error": "^1.0.30",
36
- "opticore-dependency-inject": "^1.0.11",
37
- "opticore-env-access": "^1.0.25",
35
+ "opticore-catch-exception-error": "^1.0.32",
36
+ "opticore-dependency-inject": "^1.0.13",
37
+ "opticore-env-access": "^1.0.28",
38
38
  "opticore-express": "^1.0.9",
39
- "opticore-http-response": "^1.0.11",
40
- "opticore-loader-translation": "^1.0.10",
41
- "opticore-logger": "^1.0.33",
42
- "opticore-request-call-event": "^1.0.18",
43
- "opticore-router": "^1.0.22",
44
- "opticore-server-logger": "^1.0.15",
45
- "opticore-translator": "^1.0.17",
46
- "opticore-watcher": "^1.0.32"
39
+ "opticore-http-response": "^1.0.13",
40
+ "opticore-loader-translation": "^1.0.12",
41
+ "opticore-logger": "^1.0.36",
42
+ "opticore-request-call-event": "^1.0.20",
43
+ "opticore-router": "^1.0.26",
44
+ "opticore-server-logger": "^1.0.18",
45
+ "opticore-translator": "^1.0.19",
46
+ "opticore-watcher": "^1.0.34"
47
47
  },
48
48
  "overrides": {
49
49
  "js-yaml": "^4.2.0",