Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove buildStaticHostname server logic #1745

Merged
merged 1 commit into from
Nov 15, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 2 additions & 39 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1131,12 +1131,6 @@ function initializePolisHelpers() {
"", // for API
];

let whitelistedBuckets = {
"pol.is": "pol.is",
"embed.pol.is": "pol.is",
"survey.pol.is": "survey.pol.is",
"preprod.pol.is": "preprod.pol.is",
};
function hasWhitelistMatches(host: string) {
let hostWithoutProtocol = host;
if (host.startsWith("http://")) {
Expand Down Expand Up @@ -13330,7 +13324,7 @@ Thanks for using Polis!
}

function proxy(req: { headers?: { host: string }; path: any }, res: any) {
let hostname = buildStaticHostname(req, res);
let hostname = Config.staticFilesHost;
if (!hostname) {
let host = req?.headers?.host || "";
let re = new RegExp(Config.getServerHostname() + "$");
Expand Down Expand Up @@ -13367,37 +13361,6 @@ Thanks for using Polis!
// }
}

function buildStaticHostname(req: { headers?: { host: string } }, res: any) {
if (devMode || domainOverride) {
return Config.staticFilesHost;
} else {
let origin = req?.headers?.host;
// Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ "pol.is": string; "embed.pol.is": string; "survey.pol.is": string; "preprod.pol.is": string; }'.
// No index signature with a parameter of type 'string' was found on type '{ "pol.is": string; "embed.pol.is": string; "survey.pol.is": string; "preprod.pol.is": string; }'.ts(7053)
// @ts-ignore
if (!whitelistedBuckets[origin || ""]) {
if (hasWhitelistMatches(origin || "")) {
// Use the prod bucket for non pol.is domains
return (
whitelistedBuckets["pol.is"] + "." + Config.staticFilesHost
);
} else {
logger.error(
"got request with host that's not whitelisted: (" +
req?.headers?.host +
")"
);
return;
}
}
// Element implicitly has an 'any' type because expression of type 'string' can't be used to index type '{ "pol.is": string; "embed.pol.is": string; "survey.pol.is": string; "preprod.pol.is": string; }'.
// No index signature with a parameter of type 'string' was found on type '{ "pol.is": string; "embed.pol.is": string; "survey.pol.is": string; "preprod.pol.is": string; }'.ts(7053)
// @ts-ignore
origin = whitelistedBuckets[origin || ""];
return origin + "." + Config.staticFilesHost;
}
}

function makeRedirectorTo(path: string) {
return function (
req: { headers?: { host: string } },
Expand Down Expand Up @@ -13473,7 +13436,7 @@ Thanks for using Polis!
req: { headers?: { host: any }; path: any; pipe: (arg0: any) => void },
res: { set: (arg0: any) => void }
) {
let hostname = buildStaticHostname(req, res);
let hostname = Config.staticFilesHost;
if (!hostname) {
fail(res, 500, "polis_err_file_fetcher_serving_to_domain");
return;
Expand Down
Loading