diff --git a/keyserver/src/creators/report-creator.js b/keyserver/src/creators/report-creator.js --- a/keyserver/src/creators/report-creator.js +++ b/keyserver/src/creators/report-creator.js @@ -27,7 +27,7 @@ import { handleAsyncPromise } from '../responders/handlers'; import { createBotViewer } from '../session/bots'; import type { Viewer } from '../session/viewer'; -import { getCommAppURLFacts } from '../utils/urls'; +import { getAndAssertCommAppURLFacts } from '../utils/urls'; import createIDs from './id-creator'; import createMessages from './message-creator'; @@ -144,7 +144,7 @@ const { platform, codeVersion } = platformDetails; const platformString = codeVersion ? `${platform} v${codeVersion}` : platform; if (request.type === reportTypes.ERROR) { - const { baseDomain, basePath } = getCommAppURLFacts(); + const { baseDomain, basePath } = getAndAssertCommAppURLFacts(); return ( `${name} got an error :(\n` + `using ${platformString}\n` + diff --git a/keyserver/src/fetchers/upload-fetchers.js b/keyserver/src/fetchers/upload-fetchers.js --- a/keyserver/src/fetchers/upload-fetchers.js +++ b/keyserver/src/fetchers/upload-fetchers.js @@ -5,7 +5,7 @@ import { dbQuery, SQL } from '../database/database'; import type { Viewer } from '../session/viewer'; -import { getCommAppURLFacts } from '../utils/urls'; +import { getAndAssertCommAppURLFacts } from '../utils/urls'; type UploadInfo = { content: Buffer, @@ -75,7 +75,7 @@ } function getUploadURL(id: string, secret: string): string { - const { baseDomain, basePath } = getCommAppURLFacts(); + const { baseDomain, basePath } = getAndAssertCommAppURLFacts(); return `${baseDomain}${basePath}upload/${id}/${secret}`; } diff --git a/keyserver/src/keyserver.js b/keyserver/src/keyserver.js --- a/keyserver/src/keyserver.js +++ b/keyserver/src/keyserver.js @@ -41,8 +41,8 @@ await prefetchAllURLFacts(); const squadCalBaseRoutePath = getSquadCalURLFacts()?.baseRoutePath; - const landingBaseRoutePath = getLandingURLFacts().baseRoutePath; - const commAppBaseRoutePath = getCommAppURLFacts().baseRoutePath; + const landingBaseRoutePath = getLandingURLFacts()?.baseRoutePath; + const commAppBaseRoutePath = getCommAppURLFacts()?.baseRoutePath; const compiledFolderOptions = process.env.NODE_ENV === 'development' @@ -134,21 +134,25 @@ // and prevent commAppRouter and landingRouter from working correctly. So we // make sure that squadCalRouter goes last - const landingRouter = express.Router(); - landingRouter.use('/images', express.static('images')); - landingRouter.use('/fonts', express.static('fonts')); - landingRouter.use( - '/compiled', - express.static('landing_compiled', compiledFolderOptions), - ); - landingRouter.use('/', express.static('landing_icons')); - landingRouter.post('/subscribe_email', emailSubscriptionResponder); - landingRouter.get('*', landingHandler); - server.use(landingBaseRoutePath, landingRouter); - - const commAppRouter = express.Router(); - setupAppRouter(commAppRouter); - server.use(commAppBaseRoutePath, commAppRouter); + if (landingBaseRoutePath) { + const landingRouter = express.Router(); + landingRouter.use('/images', express.static('images')); + landingRouter.use('/fonts', express.static('fonts')); + landingRouter.use( + '/compiled', + express.static('landing_compiled', compiledFolderOptions), + ); + landingRouter.use('/', express.static('landing_icons')); + landingRouter.post('/subscribe_email', emailSubscriptionResponder); + landingRouter.get('*', landingHandler); + server.use(landingBaseRoutePath, landingRouter); + } + + if (commAppBaseRoutePath) { + const commAppRouter = express.Router(); + setupAppRouter(commAppRouter); + server.use(commAppBaseRoutePath, commAppRouter); + } if (squadCalBaseRoutePath) { const squadCalRouter = express.Router(); diff --git a/keyserver/src/responders/landing-handler.js b/keyserver/src/responders/landing-handler.js --- a/keyserver/src/responders/landing-handler.js +++ b/keyserver/src/responders/landing-handler.js @@ -9,7 +9,10 @@ import { type LandingSSRProps } from '../landing/landing-ssr.react'; import { waitForStream } from '../utils/json-stream'; -import { getLandingURLFacts, clientPathFromRouterPath } from '../utils/urls'; +import { + getAndAssertLandingURLFacts, + clientPathFromRouterPath, +} from '../utils/urls'; import { getMessageForException } from './utils'; async function landingHandler(req: $Request, res: $Response) { @@ -91,8 +94,6 @@ } } -const urlFacts = getLandingURLFacts(); -const { basePath } = urlFacts; const { renderToNodeStream } = ReactDOMServer; async function landingResponder(req: $Request, res: $Response) { @@ -105,6 +106,9 @@ .map(url => ``) .join(''); + const urlFacts = getAndAssertLandingURLFacts(); + const { basePath } = urlFacts; + // prettier-ignore res.write(html` diff --git a/keyserver/src/utils/urls.js b/keyserver/src/utils/urls.js --- a/keyserver/src/utils/urls.js +++ b/keyserver/src/utils/urls.js @@ -46,8 +46,12 @@ return cachedURLFacts.get('squadcal'); } -function getCommAppURLFacts(): AppURLFacts { - const urlFacts = cachedURLFacts.get('commapp'); +function getCommAppURLFacts(): ?AppURLFacts { + return cachedURLFacts.get('commapp'); +} + +function getAndAssertCommAppURLFacts(): AppURLFacts { + const urlFacts = getCommAppURLFacts(); invariant(urlFacts, 'keyserver/facts/commapp_url.json missing'); return urlFacts; } @@ -64,8 +68,12 @@ invariant(false, 'request received but no URL facts are present'); } -function getLandingURLFacts(): AppURLFacts { - const urlFacts = cachedURLFacts.get('landing'); +function getLandingURLFacts(): ?AppURLFacts { + return cachedURLFacts.get('landing'); +} + +function getAndAssertLandingURLFacts(): AppURLFacts { + const urlFacts = getLandingURLFacts(); invariant(urlFacts, 'keyserver/facts/landing_url.json missing'); return urlFacts; } @@ -82,7 +90,9 @@ prefetchAllURLFacts, getSquadCalURLFacts, getCommAppURLFacts, + getAndAssertCommAppURLFacts, getLandingURLFacts, + getAndAssertLandingURLFacts, getAppURLFactsFromRequestURL, clientPathFromRouterPath, };