chore: respond to hub request with reflexive address #2736
@ -1,7 +1,7 @@
|
|||||||
import type { RequestHandler } from "express";
|
import type { RequestHandler } from "express";
|
||||||
|
import { getReflexiveAddress } from "../../services/configService.ts";
|
||||||
|
|
||||||
const hubController: RequestHandler = (_req, res) => {
|
export const hubController: RequestHandler = (req, res) => {
|
||||||
res.json("hub 127.0.0.1:6952");
|
const { myAddress } = getReflexiveAddress(req);
|
||||||
|
res.json(`hub ${myAddress}:6952`);
|
||||||
};
|
};
|
||||||
|
|
||||||
export { hubController };
|
|
||||||
|
|||||||
@ -1,6 +1,6 @@
|
|||||||
import type { RequestHandler } from "express";
|
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 { buildConfig } from "../../services/buildConfigService.ts";
|
||||||
|
|
||||||
import { Account } from "../../models/loginModel.ts";
|
import { Account } from "../../models/loginModel.ts";
|
||||||
@ -20,21 +20,7 @@ export const loginController: RequestHandler = async (request, response) => {
|
|||||||
? request.query.buildLabel.split(" ").join("+")
|
? request.query.buildLabel.split(" ").join("+")
|
||||||
: buildConfig.buildLabel;
|
: buildConfig.buildLabel;
|
||||||
|
|
||||||
let myAddress: string;
|
const { myAddress, myUrlBase } = getReflexiveAddress(request);
|
||||||
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 &&
|
||||||
|
|||||||
@ -3,6 +3,7 @@ import path from "path";
|
|||||||
import { repoDir } from "../helpers/pathHelper.ts";
|
import { repoDir } from "../helpers/pathHelper.ts";
|
||||||
import { args } from "../helpers/commandLineArguments.ts";
|
import { args } from "../helpers/commandLineArguments.ts";
|
||||||
import { Inbox } from "../models/inboxModel.ts";
|
import { Inbox } from "../models/inboxModel.ts";
|
||||||
|
import type { Request } from "express";
|
||||||
|
|
||||||
export interface IConfig {
|
export interface IConfig {
|
||||||
mongodbUrl: string;
|
mongodbUrl: string;
|
||||||
@ -165,3 +166,22 @@ export const syncConfigWithDatabase = (): void => {
|
|||||||
void Inbox.deleteMany({ goalTag: "GalleonRobbery" }).then(() => {});
|
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 };
|
||||||
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user