@meridianjs/framework 0.1.6 → 0.1.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.
Files changed (2) hide show
  1. package/dist/index.js +31 -8
  2. package/package.json +5 -3
package/dist/index.js CHANGED
@@ -32,6 +32,9 @@ function wrapContainer(raw) {
32
32
  },
33
33
  createScope() {
34
34
  return wrapContainer(raw.createScope());
35
+ },
36
+ async dispose() {
37
+ await raw.dispose();
35
38
  }
36
39
  };
37
40
  return container;
@@ -506,6 +509,7 @@ import cors from "cors";
506
509
  import helmet from "helmet";
507
510
  function createServer(container, config) {
508
511
  const app = express();
512
+ app.set("trust proxy", 1);
509
513
  const logger = container.resolve("logger");
510
514
  app.use(express.json({ limit: "10mb" }));
511
515
  app.use(express.urlencoded({ extended: true, limit: "10mb" }));
@@ -536,8 +540,10 @@ function createServer(container, config) {
536
540
  exposedHeaders: ["X-RateLimit-Limit", "X-RateLimit-Remaining", "X-RateLimit-Reset"]
537
541
  })
538
542
  );
539
- app.use((req, _res, next) => {
543
+ app.use((req, res, next) => {
540
544
  req.scope = container.createScope();
545
+ res.on("finish", () => req.scope.dispose?.());
546
+ res.on("close", () => req.scope.dispose?.());
541
547
  next();
542
548
  });
543
549
  app.get("/health", (_req, res) => {
@@ -657,18 +663,34 @@ async function bootstrap(opts) {
657
663
  await bus.close?.();
658
664
  } catch {
659
665
  }
666
+ try {
667
+ const scheduler = container.resolve("scheduler");
668
+ await scheduler.close();
669
+ } catch {
670
+ }
660
671
  logger.info("Meridian server stopped.");
661
672
  }
662
673
  };
663
674
  }
664
675
  async function loadMiddlewares(server, container, apiDir) {
665
676
  const logger = container.resolve("logger");
666
- const middlewaresPath = path8.join(apiDir, "middlewares.ts");
667
- let mod;
668
- try {
669
- const { pathToFileURL: pathToFileURL8 } = await import("url");
670
- mod = await import(pathToFileURL8(middlewaresPath).href);
671
- } catch {
677
+ const candidates = [
678
+ path8.join(apiDir, "middlewares.ts"),
679
+ path8.join(apiDir, "middlewares.mts"),
680
+ path8.join(apiDir, "middlewares.js"),
681
+ path8.join(apiDir, "middlewares.mjs")
682
+ ];
683
+ let mod = null;
684
+ const { pathToFileURL: pathToFileURL8 } = await import("url");
685
+ for (const candidate of candidates) {
686
+ try {
687
+ mod = await import(pathToFileURL8(candidate).href);
688
+ break;
689
+ } catch (err) {
690
+ if (err.code !== "ERR_MODULE_NOT_FOUND" && err.code !== "MODULE_NOT_FOUND") throw err;
691
+ }
692
+ }
693
+ if (!mod) {
672
694
  return;
673
695
  }
674
696
  const config = mod.default;
@@ -751,7 +773,8 @@ var SseManager = class {
751
773
  broadcast(workspaceId, event, data) {
752
774
  const set = this.clients.get(workspaceId);
753
775
  if (!set?.size) return;
754
- const payload = `event: ${event}
776
+ const safeEvent = event.replace(/[\r\n]/g, "");
777
+ const payload = `event: ${safeEvent}
755
778
  data: ${JSON.stringify(data)}
756
779
 
757
780
  `;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@meridianjs/framework",
3
- "version": "0.1.6",
3
+ "version": "0.1.7",
4
4
  "description": "Core Meridian framework: bootstrap, DI container, module/route/subscriber/job loaders",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.js",
@@ -8,8 +8,10 @@
8
8
  "type": "module",
9
9
  "exports": {
10
10
  ".": {
11
- "types": "./dist/index.d.ts",
12
- "import": "./dist/index.js"
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
13
15
  }
14
16
  },
15
17
  "scripts": {