xxscreeps-mod-client 0.3.6 → 0.3.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/backend.js +19 -25
  2. package/package.json +2 -2
package/backend.js CHANGED
@@ -58,17 +58,17 @@ function normalizeMount(input) {
58
58
  const mountPath = normalizeMount(process.env.SCREEPS_MOD_CLIENT_MOUNT_PATH ?? '/')
59
59
  const rootRedirect = readBool('SCREEPS_MOD_CLIENT_ROOT_REDIRECT', mountPath !== '/')
60
60
 
61
- // Paths that should never be handled by the client mod, even when mounted at '/'.
62
- // Can be overridden via SCREEPS_MOD_CLIENT_EXCLUDE (comma-separated prefixes).
63
- // Note: /assets/ is reserved by the game server; the client bundle uses /_client/ instead.
64
- // Do NOT exclude /map/ it's a client-side SPA route (/map/<shard>). xxscreeps has no
65
- // HTTP route there (map-stats is under /api/, map render assets under /assets/, the map
66
- // renderer is a websocket), and the await-next()-then-404-fallback below already leaves
67
- // any real server route untouched.
68
- const DEFAULT_EXCLUDES = ['/api/', '/socket', '/backend/', '/auth/', '/assets/']
69
- const excludePrefixes = process.env.SCREEPS_MOD_CLIENT_EXCLUDE
70
- ? process.env.SCREEPS_MOD_CLIENT_EXCLUDE.split(',').map(s => s.trim()).filter(Boolean)
71
- : DEFAULT_EXCLUDES
61
+ // Top-level client SPA routes. A path that isn't a real file in dist/ but matches
62
+ // one of these is a client-side deep link (or a reload of one) and gets the SPA
63
+ // shell; every other path is handed to xxscreeps, so its API/website routes are
64
+ // never shadowed and genuinely-unknown paths get a real 404 instead of the shell.
65
+ // Mirrors the route table in screeps-client/src/stores/routeStore.ts +
66
+ // utils/gameRoutes.ts keep in sync when the client gains a new top-level route.
67
+ const SPA_ROUTES = ['/user', '/profile', '/messages', '/market', '/room-overview', '/map', '/room']
68
+
69
+ function isSpaRoute(relPath) {
70
+ return SPA_ROUTES.some(prefix => relPath === prefix || relPath.startsWith(prefix + '/'))
71
+ }
72
72
 
73
73
  function resolveFile(relPath) {
74
74
  const rel = relPath.replace(/^\/+/, '')
@@ -135,9 +135,6 @@ hooks.register('middleware', koa => {
135
135
 
136
136
  const mountDisplay = mountPath === '/' ? '/' : mountPath + '/'
137
137
  console.log(`[xxscreeps-mod-client] serving client at ${mountDisplay} (rootRedirect=${rootRedirect})`)
138
- if (mountPath === '/') {
139
- console.log(`[xxscreeps-mod-client] excluded prefixes: ${excludePrefixes.join(', ')}`)
140
- }
141
138
 
142
139
  koa.use(async (ctx, next) => {
143
140
  if (ctx.method !== 'GET' && ctx.method !== 'HEAD') return next()
@@ -149,8 +146,6 @@ hooks.register('middleware', koa => {
149
146
 
150
147
  let relPath
151
148
  if (mountPath === '/') {
152
- // When mounted at root, skip paths that belong to the game server.
153
- if (excludePrefixes.some(p => ctx.path.startsWith(p))) return next()
154
149
  relPath = ctx.path
155
150
  } else if (ctx.path === mountPath || ctx.path === mountPath + '/') {
156
151
  relPath = '/'
@@ -172,14 +167,13 @@ hooks.register('middleware', koa => {
172
167
  return
173
168
  }
174
169
 
175
- // Otherwise let xxscreeps handle the request. If it 404s and the path
176
- // looks like an SPA route (no file extension on the last segment),
177
- // fall back to index.html so client-side routing can take over.
178
- await next()
179
- if (ctx.status !== 404) return
180
- const last = relPath.split('/').pop() ?? ''
181
- if (last.includes('.')) return
182
- ctx.status = 200
183
- sendInjectedIndex(ctx)
170
+ // Not a real file: claim only the client's own SPA routes (deep links and
171
+ // reloads) with the index shell, and leave every other path to xxscreeps.
172
+ if (isSpaRoute(relPath)) {
173
+ sendInjectedIndex(ctx)
174
+ return
175
+ }
176
+
177
+ return next()
184
178
  })
185
179
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xxscreeps-mod-client",
3
- "version": "0.3.6",
3
+ "version": "0.3.7",
4
4
  "description": "xxscreeps mod that serves the screeps-client and connects it to the same server.",
5
5
  "type": "module",
6
6
  "xxscreeps": true,
@@ -23,7 +23,7 @@
23
23
  "node": ">=20"
24
24
  },
25
25
  "dependencies": {
26
- "screeps-client": "^0.17.0"
26
+ "screeps-client": "^0.17.1"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "xxscreeps": "*"