Fix compiling errors

This commit is contained in:
fflorent 2024-04-18 18:51:43 +02:00
parent 968d14d702
commit 3722fcddf3
3 changed files with 14 additions and 16 deletions

View File

@ -773,10 +773,10 @@ export class UserAPIImpl extends BaseAPI implements UserAPI {
} }
public async getWorker(key: string): Promise<string> { public async getWorker(key: string): Promise<string> {
const json = await this.requestJson(`${this._url}/api/worker/${key}`, { const json: PublicDocWorkerUrlInfo = (await this.requestJson(`${this._url}/api/worker/${key}`, {
method: 'GET', method: 'GET',
credentials: 'include' credentials: 'include'
}); })) as PublicDocWorkerUrlInfo;
return getPublicDocWorkerUrl(this._homeUrl, json); return getPublicDocWorkerUrl(this._homeUrl, json);
} }
@ -1168,7 +1168,7 @@ export type PublicDocWorkerUrlInfo = {
docWorkerUrl: null; docWorkerUrl: null;
} | { } | {
selfPrefix: null; selfPrefix: null;
docWorkerUrl: string|null; docWorkerUrl: string;
} }
export function getUrlFromPrefix(homeUrl: string, prefix: string) { export function getUrlFromPrefix(homeUrl: string, prefix: string) {
@ -1191,6 +1191,7 @@ export function getUrlFromPrefix(homeUrl: string, prefix: string) {
* (result of the call to /api/worker/:docId) * (result of the call to /api/worker/:docId)
*/ */
export function getPublicDocWorkerUrl(homeUrl: string, docWorkerInfo: PublicDocWorkerUrlInfo) { export function getPublicDocWorkerUrl(homeUrl: string, docWorkerInfo: PublicDocWorkerUrlInfo) {
const publicUrl = docWorkerInfo.docWorkerUrl; return docWorkerInfo.selfPrefix ?
return publicUrl || getUrlFromPrefix(homeUrl, docWorkerInfo?.selfPrefix); getUrlFromPrefix(homeUrl, docWorkerInfo.selfPrefix) :
docWorkerInfo.docWorkerUrl!;
} }

View File

@ -195,10 +195,16 @@ export function attachAppEndpoint(options: AttachOptions): void {
}); });
} }
// When no doc worker seed, we're in single server mode.
// Return null, to signify that the URL prefix serving the
// current endpoint is the only one available.
const publicUrl = docStatus?.docWorker?.publicUrl;
const workerPublicUrl = publicUrl !== undefined ? customizeDocWorkerUrl(publicUrl, req) : null;
await sendAppPage(req, res, {path: "", content: body.page, tag: body.tag, status: 200, await sendAppPage(req, res, {path: "", content: body.page, tag: body.tag, status: 200,
googleTagManager: 'anon', config: { googleTagManager: 'anon', config: {
assignmentId: docId, assignmentId: docId,
getWorker: {[docId]: customizeDocWorkerUrl(docStatus?.docWorker?.publicUrl, req)}, getWorker: {[docId]: workerPublicUrl },
getDoc: {[docId]: pruneAPIResult(doc as unknown as APIDocument)}, getDoc: {[docId]: pruneAPIResult(doc as unknown as APIDocument)},
plugins plugins
}}); }});

View File

@ -36,16 +36,7 @@ import { getAssignmentId } from './idUtils';
* TODO: doc worker registration could be redesigned to remove the assumption * TODO: doc worker registration could be redesigned to remove the assumption
* of a fixed base domain. * of a fixed base domain.
*/ */
export function customizeDocWorkerUrl( export function customizeDocWorkerUrl( docWorkerUrlSeed: string, req: express.Request): string {
docWorkerUrlSeed: string|undefined,
req: express.Request
): string|null {
if (!docWorkerUrlSeed) {
// When no doc worker seed, we're in single server mode.
// Return null, to signify that the URL prefix serving the
// current endpoint is the only one available.
return null;
}
const docWorkerUrl = new URL(docWorkerUrlSeed); const docWorkerUrl = new URL(docWorkerUrlSeed);
const workerSubdomain = parseSubdomainStrictly(docWorkerUrl.hostname).org; const workerSubdomain = parseSubdomainStrictly(docWorkerUrl.hostname).org;
adaptServerUrl(docWorkerUrl, req); adaptServerUrl(docWorkerUrl, req);