xxscreeps-mod-client 0.2.4 → 0.2.5

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 +17 -4
  2. package/package.json +2 -2
package/backend.js CHANGED
@@ -42,8 +42,15 @@ 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
+ const DEFAULT_EXCLUDES = ['/api/', '/socket', '/backend/', '/auth/', '/assets/', '/map/']
51
+ const excludePrefixes = process.env.SCREEPS_MOD_CLIENT_EXCLUDE
52
+ ? process.env.SCREEPS_MOD_CLIENT_EXCLUDE.split(',').map(s => s.trim()).filter(Boolean)
53
+ : DEFAULT_EXCLUDES
47
54
 
48
55
  function resolveFile(relPath) {
49
56
  const rel = relPath.replace(/^\/+/, '')
@@ -86,18 +93,24 @@ hooks.register('middleware', koa => {
86
93
  return
87
94
  }
88
95
 
89
- console.log(`[xxscreeps-mod-client] serving client at ${mountPath === '/' ? '/' : mountPath + '/'} (rootRedirect=${rootRedirect})`)
96
+ const mountDisplay = mountPath === '/' ? '/' : mountPath + '/'
97
+ console.log(`[xxscreeps-mod-client] serving client at ${mountDisplay} (rootRedirect=${rootRedirect})`)
98
+ if (mountPath === '/') {
99
+ console.log(`[xxscreeps-mod-client] excluded prefixes: ${excludePrefixes.join(', ')}`)
100
+ }
90
101
 
91
102
  koa.use(async (ctx, next) => {
92
103
  if (ctx.method !== 'GET' && ctx.method !== 'HEAD') return next()
93
104
 
94
- if (mountPath !== '/' && ctx.path === '/' && rootRedirect) {
105
+ if (ctx.path === '/' && rootRedirect && mountPath !== '/') {
95
106
  ctx.redirect(mountPath + '/')
96
107
  return
97
108
  }
98
109
 
99
110
  let relPath
100
111
  if (mountPath === '/') {
112
+ // When mounted at root, skip paths that belong to the game server.
113
+ if (excludePrefixes.some(p => ctx.path.startsWith(p))) return next()
101
114
  relPath = ctx.path
102
115
  } else if (ctx.path === mountPath || ctx.path === mountPath + '/') {
103
116
  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.5",
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.0"
27
27
  },
28
28
  "peerDependencies": {
29
29
  "xxscreeps": "*"