@colyseus/monitor 0.18.2 → 0.18.4

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.
@@ -6,7 +6,7 @@
6
6
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
7
7
  <link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
8
8
  <title>Colyseus Stats</title>
9
- <script type="module" crossorigin src="./assets/index-CtJMymAb.js"></script>
9
+ <script type="module" crossorigin src="./assets/index-A9dDB1WV.js"></script>
10
10
  <link rel="stylesheet" crossorigin href="./assets/index-C4SPBCkT.css">
11
11
  </head>
12
12
  <body>
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@colyseus/monitor",
3
- "version": "0.18.2",
3
+ "version": "0.18.4",
4
4
  "type": "module",
5
5
  "description": "Web Monitoring Panel for Colyseus",
6
6
  "input": "./src/index.ts",
@@ -71,7 +71,7 @@
71
71
  "dependencies": {
72
72
  "node-os-utils": "^2.0.0",
73
73
  "zod": "^4.1.12",
74
- "@colyseus/core": "^0.18.5"
74
+ "@colyseus/core": "^0.18.14"
75
75
  },
76
76
  "publishConfig": {
77
77
  "tag": "next"
@@ -1,4 +1,3 @@
1
- import fs from 'fs/promises';
2
1
  import path from 'path';
3
2
  import { z } from 'zod';
4
3
  import { createEndpoint, dualModeEndpoints, matchMaker, type Endpoint } from '@colyseus/core';
@@ -12,7 +11,7 @@ const UNAVAILABLE_ROOM_ERROR = "@colyseus/monitor: room $roomId is not available
12
11
  const SPA_DIST = path.resolve(import.meta.dirname, '..', 'build', 'static');
13
12
 
14
13
  export interface MonitorOptions {
15
- /** Mount prefix used when spread into `createRouter`. Ignored in express-middleware mode. Defaults to `''`. */
14
+ /** Endpoint path prefix namespaces the routes when spread into `createRouter`, honored at root express mounts. Under a path mount (`app.use("/stats", monitor())`) the mount path takes over. Defaults to `'/monitor'`. */
16
15
  prefix?: string;
17
16
  /** Better-call middleware applied to every monitor endpoint — use for auth gating. */
18
17
  use?: any[];
@@ -65,7 +64,8 @@ export function monitor(opts: MonitorOptions = {}) {
65
64
  }),
66
65
  connections,
67
66
  cpu,
68
- memory: { totalMemMb, usedMemMb },
67
+ // rssMb is this process only — processId says which one it is
68
+ memory: { totalMemMb, usedMemMb, rssMb: process.memoryUsage.rss() / 1024 / 1024, processId: matchMaker.processId },
69
69
  };
70
70
  } catch (e: any) {
71
71
  console.error(e.message);
@@ -119,45 +119,9 @@ export function monitor(opts: MonitorOptions = {}) {
119
119
  }),
120
120
  };
121
121
 
122
- const SPA_DIST_RESOLVED = path.resolve(SPA_DIST);
123
-
124
- // Express compat — works with either `app.use("/monitor", monitor())` or
125
- // `app.use("/", monitor())`. Routing decisions use originalUrl (the same
126
- // string better-call's getRequest uses to build the dispatched Request URL),
127
- // so the middleware's match check and the actual dispatch always agree.
128
122
  return dualModeEndpoints(endpoints, {
129
123
  catchAllKey: 'monitor-static',
130
- buildMiddleware: ({ specificRouter, specificHandler, fullHandler }) => (req, res, next) => {
131
- if (req.method !== 'GET') { return next(); }
132
-
133
- const dispatchUrl = ((req as any).originalUrl ?? req.url ?? '').split('?')[0]!;
134
-
135
- // Bare prefix (`/monitor`) → 301 to canonical `/monitor/`.
136
- if (prefix && dispatchUrl === prefix) {
137
- res.writeHead(301, { location: `${prefix}/` });
138
- res.end();
139
- return;
140
- }
141
-
142
- const route = specificRouter.findRoute('GET', dispatchUrl);
143
- if (route && route.data?.path === dispatchUrl) {
144
- return specificHandler(req as any, res as any).catch(next);
145
- }
146
-
147
- // Asset request — only delegate if the file exists on disk.
148
- if (!dispatchUrl.startsWith(prefix)) { return next(); }
149
- const rel = dispatchUrl.slice(prefix.length).replace(/^\/+/, '');
150
- if (!rel || rel.includes('..')) { return next(); }
151
- const filePath = path.resolve(SPA_DIST_RESOLVED, rel);
152
- if (!filePath.startsWith(SPA_DIST_RESOLVED + path.sep)) { return next(); }
153
-
154
- fs.stat(filePath).then((stat) => {
155
- if (stat.isFile()) {
156
- fullHandler(req as any, res as any).catch(next);
157
- } else {
158
- next();
159
- }
160
- }).catch(() => next());
161
- },
124
+ prefix,
125
+ staticDir: SPA_DIST,
162
126
  });
163
127
  }