Skip to content

Commit 1747d20

Browse files
authored
fix: problems with hardcoded http URLs (#42)
This adds the actual backend protocol to the options object we hack in, and replaces any occurrences of "http://" + host the client likes to do with the correct protocol. Fixes loading map tiles through http even though the backend is server over https (making it rely on having an accessible http version, which might not exist). To reproduce, open http://pandascreeps.localhost:8080/(https://server.pandascreeps.com/)/#!/map/shard0?pos=2.46,3.046 and http://pandascreeps.localhost:8080/(https://server.pandascreeps.com/)/#!/profile/Gadjung. Make sure you don't get redirected to the http version when logging in, I had that happen and it's confusing. Before the patch, the first one can be observed loading map tiles through http://server.pandascreeps.com:21025/assets/map/W0S1.png?bust=1739218060553, which happens to work but isn't technically correct. Note that I've checked the map and profile page, but that's about it. 🤞 I'm not catching something else in the middle of that batch-rewrite.
1 parent ec4d60d commit 1747d20

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/clientApp.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,8 @@ koa.use(async (context, next) => {
327327
// Inject host, port, and official
328328
src = `${src.substring(0, i)},
329329
host: ${JSON.stringify(backend.hostname)},
330-
port: ${backend.port || '80'},
330+
protocol: "${backend.protocol}",
331+
port: ${backend.port || (backend.protocol === 'https:' ? '443' : '80')},
331332
official: ${isOfficialLike},
332333
} ${src.substring(i + 1)}`;
333334
}
@@ -348,7 +349,10 @@ koa.use(async (context, next) => {
348349
}
349350

350351
// Replace URLs with local client paths
351-
src = src.replace(/https:\/\/screeps.com\/a\//g, client.getURL(Route.ROOT));
352+
src = src.replace(/https:\/\/screeps\.com\/a\//g, client.getURL(Route.ROOT));
353+
354+
// Fix the hardcoded protocol in URLs
355+
src = src.replace(/"http:\/\/"\+([^\.]+)\.options\.host/g, '$1.options.protocol+"//"+$1.options.host');
352356
}
353357
return argv.beautify ? jsBeautify(src) : src;
354358
} else if (urlPath === 'components/profile/profile.html') {

0 commit comments

Comments
 (0)