xxscreeps-mod-client 0.2.4 → 0.2.6

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 +18 -4
  2. package/package.json +2 -2
package/backend.js CHANGED
@@ -42,8 +42,16 @@ function normalizeMount(input) {
42
42
  return p === '' ? '/' : p
43
43
  }
44
44
 
45
- const mountPath = normalizeMount(process.env.SCREEPS_MOD_CLIENT_MOUNT_PATH ?? '/')
46
- const rootRedirect = readBool('SCREEPS_MOD_CLIENT_ROOT_REDIRECT', mountPath !== '/')
45
+ const mountPath = normalizeMount(process.env.SCREEPS_MOD_CLIENT_MOUNT_PATH ?? '/client')
46
+ const rootRedirect = readBool('SCREEPS_MOD_CLIENT_ROOT_REDIRECT', true)
47
+
48
+ // Paths that should never be handled by the client mod, even when mounted at '/'.
49
+ // Can be overridden via SCREEPS_MOD_CLIENT_EXCLUDE (comma-separated prefixes).
50
+ // Note: /assets/ is reserved by the game server; the client bundle uses /_client/ instead.
51
+ const DEFAULT_EXCLUDES = ['/api/', '/socket', '/backend/', '/auth/', '/assets/', '/map/']
52
+ const excludePrefixes = process.env.SCREEPS_MOD_CLIENT_EXCLUDE
53
+ ? process.env.SCREEPS_MOD_CLIENT_EXCLUDE.split(',').map(s => s.trim()).filter(Boolean)
54
+ : DEFAULT_EXCLUDES
47
55
 
48
56
  function resolveFile(relPath) {
49
57
  const rel = relPath.replace(/^\/+/, '')
@@ -86,18 +94,24 @@ hooks.register('middleware', koa => {
86
94
  return
87
95
  }
88
96
 
89
- console.log(`[xxscreeps-mod-client] serving client at ${mountPath === '/' ? '/' : mountPath + '/'} (rootRedirect=${rootRedirect})`)
97
+ const mountDisplay = mountPath === '/' ? '/' : mountPath + '/'
98
+ console.log(`[xxscreeps-mod-client] serving client at ${mountDisplay} (rootRedirect=${rootRedirect})`)
99
+ if (mountPath === '/') {
100
+ console.log(`[xxscreeps-mod-client] excluded prefixes: ${excludePrefixes.join(', ')}`)
101
+ }
90
102
 
91
103
  koa.use(async (ctx, next) => {
92
104
  if (ctx.method !== 'GET' && ctx.method !== 'HEAD') return next()
93
105
 
94
- if (mountPath !== '/' && ctx.path === '/' && rootRedirect) {
106
+ if (ctx.path === '/' && rootRedirect && mountPath !== '/') {
95
107
  ctx.redirect(mountPath + '/')
96
108
  return
97
109
  }
98
110
 
99
111
  let relPath
100
112
  if (mountPath === '/') {
113
+ // When mounted at root, skip paths that belong to the game server.
114
+ if (excludePrefixes.some(p => ctx.path.startsWith(p))) return next()
101
115
  relPath = ctx.path
102
116
  } else if (ctx.path === mountPath || ctx.path === mountPath + '/') {
103
117
  relPath = '/'
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "xxscreeps-mod-client",
3
- "version": "0.2.4",
3
+ "version": "0.2.6",
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.3.3"
26
+ "screeps-client": "^0.4.1"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "xxscreeps": "*"