Skip to content

Commit

Permalink
attempt to fix issue with duplicate doc
Browse files Browse the repository at this point in the history
  • Loading branch information
fflorent committed Mar 26, 2024
1 parent 399706a commit 680d11e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/common/UserAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1123,6 +1123,7 @@ export class DocAPIImpl extends BaseAPI implements DocAPI {
*/
export function getDocWorkerUrl(homeUrl: string, docWorkerInfo: {
docWorkerUrl: string|null,
internalDocWorkerUrl: string|null,
selfPrefix?: string,
}): string {
if (!docWorkerInfo.docWorkerUrl) {
Expand All @@ -1134,5 +1135,5 @@ export function getDocWorkerUrl(homeUrl: string, docWorkerInfo: {
url.pathname = docWorkerInfo.selfPrefix + url.pathname;
return url.href;
}
return docWorkerInfo.docWorkerUrl;
return docWorkerInfo.internalDocWorkerUrl || docWorkerInfo.docWorkerUrl;
}
7 changes: 5 additions & 2 deletions app/server/lib/AppEndpoint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ export function attachAppEndpoint(options: AttachOptions): void {
// Alternatives could be: have the client to send their base URL
// in the request; or use headers commonly added by reverse proxies.
const selfPrefix = "/dw/self/v/" + gristServer.getTag();
res.json({docWorkerUrl: null, selfPrefix});
res.json({docWorkerUrl: null, internalDocWorkerUrl: null, selfPrefix});
return;
}
if (!trustOrigin(req, res)) { throw new Error('Unrecognized origin'); }
Expand All @@ -73,7 +73,10 @@ export function attachAppEndpoint(options: AttachOptions): void {
if (!docStatus) {
return res.status(500).json({error: 'no worker'});
}
res.json({docWorkerUrl: customizeDocWorkerUrl(docStatus.docWorker.publicUrl, req)});
res.json({
docWorkerUrl: customizeDocWorkerUrl(docStatus.docWorker.publicUrl, req),
internalDocWorkerUrl: docStatus.docWorker.internalUrl
});
}));

// Handler for serving the document landing pages. Expects the following parameters:
Expand Down
5 changes: 3 additions & 2 deletions app/server/lib/FlexServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,8 +312,9 @@ export class FlexServer implements GristServer {
/**
* Same as getHomeUrl, but for requesting internally.
*/
public getHomeInternalUrl(req: express.Request, relPath?: string): string {
return this.getHomeUrl(req, relPath, this.getDefaultHomeInternalUrl());
public getHomeInternalUrl(req: express.Request, relPath: string = ''): string {
const homeUrl = new URL(relPath, this.getDefaultHomeInternalUrl());
return homeUrl.href;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions app/server/lib/requestUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ export function trustOrigin(req: Request, resp: Response): boolean {
const origin = req.get('origin');
if (!origin) { return true; } // Not a CORS request.
if (process.env.GRIST_HOST && req.hostname === process.env.GRIST_HOST) { return true; }

if (
(process.env.APP_HOME_INTERNAL_URL && req.hostname === new URL(process.env.APP_HOME_INTERNAL_URL).hostname) ||
(process.env.APP_DOC_INTERNAL_URL && req.hostname === new URL(process.env.APP_DOC_INTERNAL_URL).hostname)
) {
return true;
}

if (!allowHost(req, new URL(origin))) { return false; }

// For a request to a custom domain, the full hostname must match.
Expand Down

0 comments on commit 680d11e

Please sign in to comment.