(core) make Grist easier to run with a single server

Summary:
This makes many small changes so that Grist is less fussy to run as a single instance behind a reverse proxy. Some users had difficulty with the self-connections Grist would make, due to internal network setup, and since these are unnecessary in any case in this scenario, they are now optimized away. Likewise some users had difficulties related to doc worker urls, which are now also optimized away. With these changes, users should be able to get a lot further on first try, at least far enough to open and edit documents.

The `GRIST_SINGLE_ORG` setting was proving a bit confusing, since it appeared to only work when set to `docs`. This diff
adds a check for whether the specified org exists, and if not, it creates it. This still depends on having a user email to make as the owner of the team, so there could be remaining difficulties there.

Test Plan: tested manually with nginx

Reviewers: jarek

Reviewed By: jarek

Differential Revision: https://phab.getgrist.com/D3299
This commit is contained in:
Paul Fitzpatrick
2022-03-02 14:07:26 -05:00
parent 0da397ab90
commit 2563fb745a
13 changed files with 228 additions and 68 deletions

View File

@@ -299,7 +299,9 @@ export class HomeDBManager extends EventEmitter {
}
// make sure special users and workspaces are available
public async initializeSpecialIds(): Promise<void> {
public async initializeSpecialIds(options?: {
skipWorkspaces?: boolean // if set, skip setting example workspace.
}): Promise<void> {
await this._getSpecialUserId({
email: ANONYMOUS_USER_EMAIL,
name: "Anonymous"
@@ -317,21 +319,26 @@ export class HomeDBManager extends EventEmitter {
name: "Support"
});
// Find the example workspace. If there isn't one named just right, take the first workspace
// belonging to the support user. This shouldn't happen in deployments but could happen
// in tests.
const supportWorkspaces = await this._workspaces()
.leftJoinAndSelect('workspaces.org', 'orgs')
.where('orgs.owner_id = :userId', { userId: this.getSupportUserId() })
.orderBy('workspaces.created_at')
.getMany();
const exampleWorkspace = supportWorkspaces.find(ws => ws.name === EXAMPLE_WORKSPACE_NAME) || supportWorkspaces[0];
if (!exampleWorkspace) { throw new Error('No example workspace available'); }
if (exampleWorkspace.name !== EXAMPLE_WORKSPACE_NAME) {
log.warn('did not find an appropriately named example workspace in deployment');
if (!options?.skipWorkspaces) {
// Find the example workspace. If there isn't one named just right, take the first workspace
// belonging to the support user. This shouldn't happen in deployments but could happen
// in tests.
// TODO: it should now be possible to remove all this; the only remaining
// issue is what workspace to associate with documents created by
// anonymous users.
const supportWorkspaces = await this._workspaces()
.leftJoinAndSelect('workspaces.org', 'orgs')
.where('orgs.owner_id = :userId', { userId: this.getSupportUserId() })
.orderBy('workspaces.created_at')
.getMany();
const exampleWorkspace = supportWorkspaces.find(ws => ws.name === EXAMPLE_WORKSPACE_NAME) || supportWorkspaces[0];
if (!exampleWorkspace) { throw new Error('No example workspace available'); }
if (exampleWorkspace.name !== EXAMPLE_WORKSPACE_NAME) {
log.warn('did not find an appropriately named example workspace in deployment');
}
this._exampleWorkspaceId = exampleWorkspace.id;
this._exampleOrgId = exampleWorkspace.org.id;
}
this._exampleWorkspaceId = exampleWorkspace.id;
this._exampleOrgId = exampleWorkspace.org.id;
}
public get connection() {