Skip to content

Commit 2648f52

Browse files
authored
fix: Adjust internal URLs to match public protocol (#47)
This PR updates internal URL generation to match the configured public protocol. This solves the issue of mixed-content when serving the client via TLS; room-history (and other APIs) break when their XHR calls downgrade from TLS to unencrypted HTTP.
1 parent 144a84e commit 2648f52

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/clientApp.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ koa.use(async (context, next) => {
238238

239239
const client = new Client({
240240
host: clientHost,
241+
protocol: publicProtocol,
241242
prefix,
242243
backend: info.backend,
243244
});
@@ -253,7 +254,7 @@ koa.use(async (context, next) => {
253254
? `${client.getURL(Route.ROOT)}season/`
254255
: client.getURL(Route.ROOT, { prefix: false });
255256
const ptrLink = isOfficial && !prefix ? `${client.getURL(Route.ROOT)}ptr/` : undefined;
256-
const changeServerLink = `http://${trimLocalSubdomain(clientHost)}/`;
257+
const changeServerLink = `${publicProtocol}://${trimLocalSubdomain(clientHost)}/`;
257258

258259
// Inject startup script
259260
const header = '<title>Screeps</title>';

src/utils/client.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,13 @@ export enum Route {
2020
*/
2121
export class Client {
2222
private host: string;
23+
private protocol: string;
2324
private basePath: string;
2425
private prefix: string;
2526

26-
constructor({ host, prefix, backend }: { host: string; backend: string; prefix?: string }) {
27+
constructor({ host, protocol, prefix, backend }: { host: string; protocol?: string; backend: string; prefix?: string }) {
2728
this.host = host;
29+
this.protocol = protocol || 'http';
2830
this.basePath = `/(${backend})`;
2931
this.prefix = prefix || '';
3032
}
@@ -37,5 +39,5 @@ export class Client {
3739
this.getBasePath(opts) + (opts?.prefix !== false ? this.prefix : '') + route;
3840

3941
getURL = (route: Route, opts?: Options) =>
40-
`http://${this.getHost(opts)}${this.getPath(route, { ...opts, full: false })}`;
42+
`${this.protocol}://${this.getHost(opts)}${this.getPath(route, { ...opts, full: false })}`;
4143
}

src/utils/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export async function getServerListConfig(dirname: string, protocol: string, hos
104104

105105
return {
106106
name: type.charAt(0).toUpperCase() + type.slice(1),
107-
logo: type === 'official' ? `http://${host}:${port}/(file)/logotype.svg` : undefined,
107+
logo: type === 'official' ? `${protocol}://${host}:${port}/(file)/logotype.svg` : undefined,
108108
servers: serversOfType,
109109
};
110110
});

0 commit comments

Comments
 (0)