From 6c6bfee00e9a8af53abaf5134ac94b10a746d461 Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Tue, 5 Apr 2022 11:48:15 -0400 Subject: [PATCH] (core) fix redirects for multi-team Grist on a single domain Summary: The logic for calculating redirects wasn't quite right for Grist configured to use a single domain, with teams encoded in the path. This fixes it. Test Plan: tested manually with docker compose and /etc/hosts Reviewers: georgegevoian Reviewed By: georgegevoian Differential Revision: https://phab.getgrist.com/D3359 --- app/common/gristUrls.ts | 6 ++++++ app/server/lib/FlexServer.ts | 8 ++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/common/gristUrls.ts b/app/common/gristUrls.ts index 47357881..29a2e434 100644 --- a/app/common/gristUrls.ts +++ b/app/common/gristUrls.ts @@ -112,6 +112,9 @@ export interface OrgUrlOptions { // Base URL used for accessing plugin material. pluginUrl?: string; + + // If set, org is expected to be encoded in the path, not domain. + pathOnly?: boolean; } // Result of getOrgUrlInfo(). @@ -145,6 +148,9 @@ export function getOrgUrlInfo(newOrg: string, currentHost: string, options: OrgU if (newOrg === options.singleOrg) { return {}; } + if (options.pathOnly) { + return {orgInPath: newOrg}; + } const hostType = getHostType(currentHost, options); if (hostType !== 'plugin') { const hostname = currentHost.split(":")[0]; diff --git a/app/server/lib/FlexServer.ts b/app/server/lib/FlexServer.ts index 9ec5f292..ca6b90cc 100644 --- a/app/server/lib/FlexServer.ts +++ b/app/server/lib/FlexServer.ts @@ -1515,12 +1515,8 @@ export class FlexServer implements GristServer { * path. */ private _getOrgRedirectUrl(req: RequestWithLogin, subdomain: string, pathname: string = req.originalUrl): string { - const {hostname, orgInPath} = getOrgUrlInfo(subdomain, req.get('host')!, { - org: req.org, - baseDomain: this._defaultBaseDomain, - pluginUrl: this._pluginUrl, - singleOrg: process.env.GRIST_SINGLE_ORG, - }); + const config = this.getGristConfig(); + const {hostname, orgInPath} = getOrgUrlInfo(subdomain, req.get('host')!, config); const redirectUrl = new URL(pathname, `${req.protocol}://${req.get('host')}`); if (hostname) { redirectUrl.hostname = hostname;