返回提交历史
Modified
src/controllers/api/loginController.ts
+25
-6
XFEstudio/XFESpaceNinjaServer
fix: more robust address detection (#2099)
Previously this had a few issues when using non-standard ports for HTTP(S) Reviewed-on: https://onlyg.it/OpenWF/SpaceNinjaServer/pulls/2099 Co-authored-by: Sainan <63328889+Sainan@users.noreply.github.com> Co-committed-by: Sainan <63328889+Sainan@users.noreply.github.com>
082ae536
代码差异
1 个文件
+25
-6
@@ -20,7 +20,21 @@ export const loginController: RequestHandler = async (request, response) => {
20
20
? request.query.buildLabel.split(" ").join("+")
21
21
: buildConfig.buildLabel;
22
22
23
const myAddress = request.host.indexOf("warframe.com") == -1 ? request.host : config.myAddress;
23
let myAddress: string;
24
let myUrlBase: string = request.protocol + "://";
25
if (request.host.indexOf("warframe.com") == -1) {
26
// Client request was redirected cleanly, so we know it can reach us how it's reaching us now.
27
myAddress = request.hostname;
28
myUrlBase += request.host;
29
} else {
30
// Don't know how the client reached us, hoping the config does.
31
myAddress = config.myAddress;
32
myUrlBase += myAddress;
33
const port: number = request.protocol == "http" ? config.httpPort || 80 : config.httpsPort || 443;
34
if (port != (request.protocol == "http" ? 80 : 443)) {
35
myUrlBase += ":" + port;
36
}
37
}
24
38
25
39
if (
26
40
!account &&
@@ -52,7 +66,7 @@ export const loginController: RequestHandler = async (request, response) => {
52
66
LastLogin: new Date()
53
67
});
54
68
logger.debug("created new account");
55
response.json(createLoginResponse(myAddress, newAccount, buildLabel));
69
response.json(createLoginResponse(myAddress, myUrlBase, newAccount, buildLabel));
56
70
return;
57
71
} catch (error: unknown) {
58
72
if (error instanceof Error) {
@@ -98,10 +112,15 @@ export const loginController: RequestHandler = async (request, response) => {
98
112
}
99
113
await account.save();
100
114
101
response.json(createLoginResponse(myAddress, account.toJSON(), buildLabel));
115
response.json(createLoginResponse(myAddress, myUrlBase, account.toJSON(), buildLabel));
102
116
};
103
117
104
const createLoginResponse = (myAddress: string, account: IDatabaseAccountJson, buildLabel: string): ILoginResponse => {
118
const createLoginResponse = (
119
myAddress: string,
120
myUrlBase: string,
121
account: IDatabaseAccountJson,
122
buildLabel: string
123
): ILoginResponse => {
105
124
const resp: ILoginResponse = {
106
125
id: account.id,
107
126
DisplayName: account.DisplayName,
@@ -139,11 +158,11 @@ const createLoginResponse = (myAddress: string, account: IDatabaseAccountJson, b
139
158
}
140
159
if (version_compare(buildLabel, "2022.09.06.19.24") >= 0) {
141
160
resp.CrossPlatformAllowed = account.CrossPlatformAllowed;
142
resp.HUB = `https://${myAddress}/api/`;
161
resp.HUB = `${myUrlBase}/api/`;
143
162
resp.MatchmakingBuildId = buildConfig.matchmakingBuildId;
144
163
}
145
164
if (version_compare(buildLabel, "2023.04.25.23.40") >= 0) {
146
resp.platformCDNs = [`https://${myAddress}/`];
165
resp.platformCDNs = [`${myUrlBase}/`];
147
166
}
148
167
return resp;
149
168
};