@colyseus/monitor 0.18.1 → 0.18.3

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-CDY0bZlU.js"></script>
9
+ <script type="module" crossorigin src="./assets/index-D9MoG02G.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,7 @@
1
1
  {
2
2
  "name": "@colyseus/monitor",
3
- "version": "0.18.1",
3
+ "version": "0.18.3",
4
+ "type": "module",
4
5
  "description": "Web Monitoring Panel for Colyseus",
5
6
  "input": "./src/index.ts",
6
7
  "main": "./build/index.cjs",
@@ -42,6 +43,9 @@
42
43
  "url": "https://github.com/colyseus/colyseus/issues"
43
44
  },
44
45
  "homepage": "https://github.com/colyseus/colyseus#readme",
46
+ "engines": {
47
+ "node": ">= 22.x"
48
+ },
45
49
  "devDependencies": {
46
50
  "@emotion/react": "^11.11.1",
47
51
  "@emotion/styled": "^11.11.0",
@@ -67,7 +71,7 @@
67
71
  "dependencies": {
68
72
  "node-os-utils": "^2.0.0",
69
73
  "zod": "^4.1.12",
70
- "@colyseus/core": "^0.18.1"
74
+ "@colyseus/core": "^0.18.6"
71
75
  },
72
76
  "publishConfig": {
73
77
  "tag": "next"
@@ -1,6 +1,4 @@
1
- import fs from 'fs/promises';
2
1
  import path from 'path';
3
- import { fileURLToPath } from 'url';
4
2
  import { z } from 'zod';
5
3
  import { createEndpoint, dualModeEndpoints, matchMaker, type Endpoint } from '@colyseus/core';
6
4
  import { OSUtils } from 'node-os-utils';
@@ -10,10 +8,10 @@ import './ext/Room.js';
10
8
 
11
9
  const osutils = new OSUtils();
12
10
  const UNAVAILABLE_ROOM_ERROR = "@colyseus/monitor: room $roomId is not available anymore.";
13
- const SPA_DIST = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..', 'build', 'static');
11
+ const SPA_DIST = path.resolve(import.meta.dirname, '..', 'build', 'static');
14
12
 
15
13
  export interface MonitorOptions {
16
- /** 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'`. */
17
15
  prefix?: string;
18
16
  /** Better-call middleware applied to every monitor endpoint — use for auth gating. */
19
17
  use?: any[];
@@ -120,45 +118,9 @@ export function monitor(opts: MonitorOptions = {}) {
120
118
  }),
121
119
  };
122
120
 
123
- const SPA_DIST_RESOLVED = path.resolve(SPA_DIST);
124
-
125
- // Express compat — works with either `app.use("/monitor", monitor())` or
126
- // `app.use("/", monitor())`. Routing decisions use originalUrl (the same
127
- // string better-call's getRequest uses to build the dispatched Request URL),
128
- // so the middleware's match check and the actual dispatch always agree.
129
121
  return dualModeEndpoints(endpoints, {
130
122
  catchAllKey: 'monitor-static',
131
- buildMiddleware: ({ specificRouter, specificHandler, fullHandler }) => (req, res, next) => {
132
- if (req.method !== 'GET') { return next(); }
133
-
134
- const dispatchUrl = ((req as any).originalUrl ?? req.url ?? '').split('?')[0]!;
135
-
136
- // Bare prefix (`/monitor`) → 301 to canonical `/monitor/`.
137
- if (prefix && dispatchUrl === prefix) {
138
- res.writeHead(301, { location: `${prefix}/` });
139
- res.end();
140
- return;
141
- }
142
-
143
- const route = specificRouter.findRoute('GET', dispatchUrl);
144
- if (route && route.data?.path === dispatchUrl) {
145
- return specificHandler(req as any, res as any).catch(next);
146
- }
147
-
148
- // Asset request — only delegate if the file exists on disk.
149
- if (!dispatchUrl.startsWith(prefix)) { return next(); }
150
- const rel = dispatchUrl.slice(prefix.length).replace(/^\/+/, '');
151
- if (!rel || rel.includes('..')) { return next(); }
152
- const filePath = path.resolve(SPA_DIST_RESOLVED, rel);
153
- if (!filePath.startsWith(SPA_DIST_RESOLVED + path.sep)) { return next(); }
154
-
155
- fs.stat(filePath).then((stat) => {
156
- if (stat.isFile()) {
157
- fullHandler(req as any, res as any).catch(next);
158
- } else {
159
- next();
160
- }
161
- }).catch(() => next());
162
- },
123
+ prefix,
124
+ staticDir: SPA_DIST,
163
125
  });
164
126
  }