fix: more robust address detection (#2099)
Previously this had a few issues when using non-standard ports for HTTP(S) Reviewed-on: #2099 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
This commit is contained in:
parent
ba6cd47432
commit
082ae536f7
@ -20,7 +20,21 @@ export const loginController: RequestHandler = async (request, response) => {
|
|||||||
? request.query.buildLabel.split(" ").join("+")
|
? request.query.buildLabel.split(" ").join("+")
|
||||||
: buildConfig.buildLabel;
|
: buildConfig.buildLabel;
|
||||||
|
|
||||||
const myAddress = request.host.indexOf("warframe.com") == -1 ? request.host : config.myAddress;
|
let myAddress: string;
|
||||||
|
let myUrlBase: string = request.protocol + "://";
|
||||||
|
if (request.host.indexOf("warframe.com") == -1) {
|
||||||
|
// Client request was redirected cleanly, so we know it can reach us how it's reaching us now.
|
||||||
|
myAddress = request.hostname;
|
||||||
|
myUrlBase += request.host;
|
||||||
|
} else {
|
||||||
|
// Don't know how the client reached us, hoping the config does.
|
||||||
|
myAddress = config.myAddress;
|
||||||
|
myUrlBase += myAddress;
|
||||||
|
const port: number = request.protocol == "http" ? config.httpPort || 80 : config.httpsPort || 443;
|
||||||
|
if (port != (request.protocol == "http" ? 80 : 443)) {
|
||||||
|
myUrlBase += ":" + port;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
!account &&
|
!account &&
|
||||||
@ -52,7 +66,7 @@ export const loginController: RequestHandler = async (request, response) => {
|
|||||||
LastLogin: new Date()
|
LastLogin: new Date()
|
||||||
});
|
});
|
||||||
logger.debug("created new account");
|
logger.debug("created new account");
|
||||||
response.json(createLoginResponse(myAddress, newAccount, buildLabel));
|
response.json(createLoginResponse(myAddress, myUrlBase, newAccount, buildLabel));
|
||||||
return;
|
return;
|
||||||
} catch (error: unknown) {
|
} catch (error: unknown) {
|
||||||
if (error instanceof Error) {
|
if (error instanceof Error) {
|
||||||
@ -98,10 +112,15 @@ export const loginController: RequestHandler = async (request, response) => {
|
|||||||
}
|
}
|
||||||
await account.save();
|
await account.save();
|
||||||
|
|
||||||
response.json(createLoginResponse(myAddress, account.toJSON(), buildLabel));
|
response.json(createLoginResponse(myAddress, myUrlBase, account.toJSON(), buildLabel));
|
||||||
};
|
};
|
||||||
|
|
||||||
const createLoginResponse = (myAddress: string, account: IDatabaseAccountJson, buildLabel: string): ILoginResponse => {
|
const createLoginResponse = (
|
||||||
|
myAddress: string,
|
||||||
|
myUrlBase: string,
|
||||||
|
account: IDatabaseAccountJson,
|
||||||
|
buildLabel: string
|
||||||
|
): ILoginResponse => {
|
||||||
const resp: ILoginResponse = {
|
const resp: ILoginResponse = {
|
||||||
id: account.id,
|
id: account.id,
|
||||||
DisplayName: account.DisplayName,
|
DisplayName: account.DisplayName,
|
||||||
@ -139,11 +158,11 @@ const createLoginResponse = (myAddress: string, account: IDatabaseAccountJson, b
|
|||||||
}
|
}
|
||||||
if (version_compare(buildLabel, "2022.09.06.19.24") >= 0) {
|
if (version_compare(buildLabel, "2022.09.06.19.24") >= 0) {
|
||||||
resp.CrossPlatformAllowed = account.CrossPlatformAllowed;
|
resp.CrossPlatformAllowed = account.CrossPlatformAllowed;
|
||||||
resp.HUB = `https://${myAddress}/api/`;
|
resp.HUB = `${myUrlBase}/api/`;
|
||||||
resp.MatchmakingBuildId = buildConfig.matchmakingBuildId;
|
resp.MatchmakingBuildId = buildConfig.matchmakingBuildId;
|
||||||
}
|
}
|
||||||
if (version_compare(buildLabel, "2023.04.25.23.40") >= 0) {
|
if (version_compare(buildLabel, "2023.04.25.23.40") >= 0) {
|
||||||
resp.platformCDNs = [`https://${myAddress}/`];
|
resp.platformCDNs = [`${myUrlBase}/`];
|
||||||
}
|
}
|
||||||
return resp;
|
return resp;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user