Host comes with port

This commit is contained in:
Leo Giovanetti 2023-06-13 17:19:12 -03:00
parent 77667200ab
commit 4b295a45d4
2 changed files with 5 additions and 6 deletions

View File

@ -23,9 +23,8 @@ export function getOrgDomain(hostname: string) {
return testHostname.endsWith(`.${ahn}`);
});
if (currentHostname) {
const url = currentHostname.split(":");
// Define which is the current domain/subdomain
const slug = `${hostname}${url.length > 1 ? `:${url[1]}` : ""}`.replace(`.${currentHostname}` ?? "", "");
const slug = hostname.replace(`.${currentHostname}` ?? "", "");
return slug.indexOf(".") === -1 ? slug : null;
}
return null;

View File

@ -35,13 +35,13 @@ describe("Org Domains Utils", () => {
});
it("should handle a local web app with port url with a local subdomain hostname", () => {
Object.defineProperty(constants, 'WEBAPP_URL', {value:"https://app.cal.local:3000"});
expect(getOrgDomain("acme.cal.local")).toEqual("acme");
Object.defineProperty(constants, 'WEBAPP_URL', {value:"http://app.cal.local:3000"});
expect(getOrgDomain("acme.cal.local:3000")).toEqual("acme");
});
it("should handle a local web app with port url with a non-local subdomain hostname", () => {
Object.defineProperty(constants, 'WEBAPP_URL', {value:"https://app.cal.local:3000"});
expect(getOrgDomain("acme.cal.com")).toEqual(null);
Object.defineProperty(constants, 'WEBAPP_URL', {value:"http://app.cal.local:3000"});
expect(getOrgDomain("acme.cal.com:3000")).toEqual(null);
});
})
});