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.
- package/backend.js +19 -25
- 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
|
-
//
|
|
62
|
-
//
|
|
63
|
-
//
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
//
|
|
176
|
-
//
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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.
|
|
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.
|
|
26
|
+
"screeps-client": "^0.17.1"
|
|
27
27
|
},
|
|
28
28
|
"peerDependencies": {
|
|
29
29
|
"xxscreeps": "*"
|