chore: respond to hub request with reflexive address (#2736)
Some checks failed
Build Docker image / docker-amd64 (push) Waiting to run
Build Docker image / docker-arm64 (push) Has been cancelled
Build / build (push) Has been cancelled

Reviewed-on: #2736
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:
Sainan 2025-09-01 20:30:03 -07:00 committed by Sainan
parent e2349b361e
commit ed596aa3f3
3 changed files with 26 additions and 20 deletions

View File

@ -1,7 +1,7 @@
import type { RequestHandler } from "express";
import { getReflexiveAddress } from "../../services/configService.ts";
const hubController: RequestHandler = (_req, res) => {
res.json("hub 127.0.0.1:6952");
export const hubController: RequestHandler = (req, res) => {
const { myAddress } = getReflexiveAddress(req);
res.json(`hub ${myAddress}:6952`);
};
export { hubController };

View File

@ -1,6 +1,6 @@
import type { RequestHandler } from "express";
import { config } from "../../services/configService.ts";
import { config, getReflexiveAddress } from "../../services/configService.ts";
import { buildConfig } from "../../services/buildConfigService.ts";
import { Account } from "../../models/loginModel.ts";
@ -20,21 +20,7 @@ export const loginController: RequestHandler = async (request, response) => {
? request.query.buildLabel.split(" ").join("+")
: buildConfig.buildLabel;
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;
}
}
const { myAddress, myUrlBase } = getReflexiveAddress(request);
if (
!account &&

View File

@ -3,6 +3,7 @@ import path from "path";
import { repoDir } from "../helpers/pathHelper.ts";
import { args } from "../helpers/commandLineArguments.ts";
import { Inbox } from "../models/inboxModel.ts";
import type { Request } from "express";
export interface IConfig {
mongodbUrl: string;
@ -165,3 +166,22 @@ export const syncConfigWithDatabase = (): void => {
void Inbox.deleteMany({ goalTag: "GalleonRobbery" }).then(() => {});
}
};
export const getReflexiveAddress = (request: Request): { myAddress: string; myUrlBase: string } => {
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;
}
}
return { myAddress, myUrlBase };
};