2020-07-23 20:04:40 +00:00
|
|
|
/**
|
|
|
|
* Main entrypoint for grist-core server.
|
2020-09-24 14:34:44 +00:00
|
|
|
*
|
|
|
|
* By default, starts up on port 8484.
|
2020-07-23 20:04:40 +00:00
|
|
|
*/
|
|
|
|
|
2021-04-02 23:11:27 +00:00
|
|
|
import {isAffirmative} from 'app/common/gutil';
|
(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
2022-03-02 19:07:26 +00:00
|
|
|
import {HomeDBManager} from 'app/gen-server/lib/HomeDBManager';
|
2022-06-29 10:19:20 +00:00
|
|
|
import {TEAM_FREE_PLAN} from 'app/common/Features';
|
2021-04-02 23:11:27 +00:00
|
|
|
|
|
|
|
const debugging = isAffirmative(process.env.DEBUG) || isAffirmative(process.env.VERBOSE);
|
|
|
|
|
2020-10-28 17:37:36 +00:00
|
|
|
// Set log levels before importing anything.
|
2021-04-02 23:11:27 +00:00
|
|
|
if (!debugging) {
|
2020-10-28 17:37:36 +00:00
|
|
|
// Be a lot less noisy by default.
|
|
|
|
setDefaultEnv('GRIST_LOG_LEVEL', 'error');
|
|
|
|
setDefaultEnv('GRIST_LOG_SKIP_HTTP', 'true');
|
|
|
|
}
|
|
|
|
|
2021-08-17 15:22:30 +00:00
|
|
|
// Use a distinct cookie. Bump version to 2.
|
|
|
|
setDefaultEnv('GRIST_SESSION_COOKIE', 'grist_core2');
|
2020-10-28 17:37:36 +00:00
|
|
|
|
(core) move more tests to grist-core
Summary:
* Tie build and run-time docker base images to a consistent version (buster)
* Extend the test login system activated by GRIST_TEST_LOGIN to ease porting tests that currently rely on cognito (many)
* Make org resets work in absence of billing endpoints
* When in-memory session caches are used, add missing invalidation steps
* Pass org information through sign-ups/sign-ins more carefully
* For CORS, explicitly trust GRIST_HOST origin when set
* Move some fixtures and tests to core, focussing on tests that cover existing failures or are in the set of tests run on deployments
* Retain regular `test` target to run the test suite directly, without docker
* Add a `test:smoke` target to run a single simple test without `GRIST_TEST_LOGIN` activated
* Add a `test:docker` target to run the tests against a grist-core docker image - since tests rely on certain fixture teams/docs, added `TEST_SUPPORT_API_KEY` and `TEST_ADD_SAMPLES` flags to ease porting
The tests ported were `nbrowser` tests: `ActionLog.ts` (the first test I tend to port to anything, out of habit), `Fork.ts` (exercises a lot of doc creation paths), `HomeIntro.ts` (a lot of DocMenu exercise), and `DuplicateDocument.ts` (covers a feature known to be failing prior to this diff, the CORS tweak resolves it).
Test Plan: Manually tested via `buildtools/build_core.sh`. In follow up, I want to add running the `test:docker` target in grist-core's workflows. In jenkins, only the smoke test is run. There'd be an argument for running all tests, but they include particularly slow tests, and are duplicates of tests already run (in different configuration admittedly), so I'd like to try first just using them in grist-core to gate updates to any packaged version of Grist (the docker image currently).
Reviewers: alexmojaki
Reviewed By: alexmojaki
Subscribers: alexmojaki
Differential Revision: https://phab.getgrist.com/D3176
2021-12-10 22:42:54 +00:00
|
|
|
setDefaultEnv('GRIST_SERVE_SAME_ORIGIN', 'true');
|
|
|
|
setDefaultEnv('GRIST_SINGLE_PORT', 'true');
|
2022-02-08 18:40:48 +00:00
|
|
|
setDefaultEnv('GRIST_DEFAULT_PRODUCT', 'Free');
|
(core) move more tests to grist-core
Summary:
* Tie build and run-time docker base images to a consistent version (buster)
* Extend the test login system activated by GRIST_TEST_LOGIN to ease porting tests that currently rely on cognito (many)
* Make org resets work in absence of billing endpoints
* When in-memory session caches are used, add missing invalidation steps
* Pass org information through sign-ups/sign-ins more carefully
* For CORS, explicitly trust GRIST_HOST origin when set
* Move some fixtures and tests to core, focussing on tests that cover existing failures or are in the set of tests run on deployments
* Retain regular `test` target to run the test suite directly, without docker
* Add a `test:smoke` target to run a single simple test without `GRIST_TEST_LOGIN` activated
* Add a `test:docker` target to run the tests against a grist-core docker image - since tests rely on certain fixture teams/docs, added `TEST_SUPPORT_API_KEY` and `TEST_ADD_SAMPLES` flags to ease porting
The tests ported were `nbrowser` tests: `ActionLog.ts` (the first test I tend to port to anything, out of habit), `Fork.ts` (exercises a lot of doc creation paths), `HomeIntro.ts` (a lot of DocMenu exercise), and `DuplicateDocument.ts` (covers a feature known to be failing prior to this diff, the CORS tweak resolves it).
Test Plan: Manually tested via `buildtools/build_core.sh`. In follow up, I want to add running the `test:docker` target in grist-core's workflows. In jenkins, only the smoke test is run. There'd be an argument for running all tests, but they include particularly slow tests, and are duplicates of tests already run (in different configuration admittedly), so I'd like to try first just using them in grist-core to gate updates to any packaged version of Grist (the docker image currently).
Reviewers: alexmojaki
Reviewed By: alexmojaki
Subscribers: alexmojaki
Differential Revision: https://phab.getgrist.com/D3176
2021-12-10 22:42:54 +00:00
|
|
|
|
(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
2022-03-02 19:07:26 +00:00
|
|
|
if (!process.env.GRIST_SINGLE_ORG) {
|
|
|
|
// org identifiers in domains are fiddly to configure right, so by
|
|
|
|
// default don't do that.
|
|
|
|
setDefaultEnv('GRIST_ORG_IN_PATH', 'true');
|
|
|
|
}
|
|
|
|
|
2020-07-21 13:20:51 +00:00
|
|
|
import {updateDb} from 'app/server/lib/dbUtils';
|
|
|
|
import {main as mergedServerMain} from 'app/server/mergedServerMain';
|
|
|
|
import * as fse from 'fs-extra';
|
|
|
|
|
|
|
|
const G = {
|
|
|
|
port: parseInt(process.env.PORT!, 10) || 8484,
|
|
|
|
};
|
|
|
|
|
2020-09-24 14:34:44 +00:00
|
|
|
// Set a default for an environment variable.
|
|
|
|
function setDefaultEnv(name: string, value: string) {
|
|
|
|
if (process.env[name] === undefined) {
|
|
|
|
process.env[name] = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-28 17:37:36 +00:00
|
|
|
// tslint:disable:no-console
|
2020-07-21 13:20:51 +00:00
|
|
|
export async function main() {
|
2020-10-28 17:37:36 +00:00
|
|
|
console.log('Welcome to Grist.');
|
2021-04-02 23:11:27 +00:00
|
|
|
if (!debugging) {
|
2020-10-28 17:37:36 +00:00
|
|
|
console.log(`In quiet mode, see http://localhost:${G.port} to use.`);
|
|
|
|
console.log('For full logs, re-run with DEBUG=1');
|
|
|
|
}
|
|
|
|
|
2021-08-17 15:22:30 +00:00
|
|
|
// If SAML is not configured, there's no login system, so provide a default email address.
|
(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
2022-03-02 19:07:26 +00:00
|
|
|
setDefaultEnv('GRIST_DEFAULT_EMAIL', 'you@example.com');
|
2020-09-24 14:34:44 +00:00
|
|
|
// Set directory for uploaded documents.
|
2020-10-28 17:37:36 +00:00
|
|
|
setDefaultEnv('GRIST_DATA_DIR', 'docs');
|
2020-09-24 14:34:44 +00:00
|
|
|
await fse.mkdirp(process.env.GRIST_DATA_DIR!);
|
2020-07-21 13:20:51 +00:00
|
|
|
// Make a blank db if needed.
|
|
|
|
await updateDb();
|
2022-05-11 19:05:35 +00:00
|
|
|
const db = new HomeDBManager();
|
|
|
|
await db.connect();
|
|
|
|
await db.initializeSpecialIds({skipWorkspaces: true});
|
|
|
|
|
(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
2022-03-02 19:07:26 +00:00
|
|
|
// If a team/organization is specified, make sure it exists.
|
|
|
|
const org = process.env.GRIST_SINGLE_ORG;
|
|
|
|
if (org && org !== 'docs') {
|
|
|
|
try {
|
|
|
|
db.unwrapQueryResult(await db.getOrg({
|
|
|
|
userId: db.getPreviewerUserId(),
|
|
|
|
includeSupport: false,
|
|
|
|
}, org));
|
|
|
|
} catch(e) {
|
|
|
|
if (!String(e).match(/organization not found/)) {
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
const email = process.env.GRIST_DEFAULT_EMAIL;
|
|
|
|
if (!email) {
|
|
|
|
throw new Error('need GRIST_DEFAULT_EMAIL to create site');
|
|
|
|
}
|
2022-04-11 18:08:44 +00:00
|
|
|
const profile = {email, name: email};
|
|
|
|
const user = await db.getUserByLogin(email, {profile});
|
(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
2022-03-02 19:07:26 +00:00
|
|
|
if (!user) {
|
|
|
|
// This should not happen.
|
|
|
|
throw new Error('failed to create GRIST_DEFAULT_EMAIL user');
|
|
|
|
}
|
2022-09-29 12:14:10 +00:00
|
|
|
db.unwrapQueryResult(await db.addOrg(user, {
|
(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
2022-03-02 19:07:26 +00:00
|
|
|
name: org,
|
|
|
|
domain: org,
|
|
|
|
}, {
|
|
|
|
setUserAsOwner: false,
|
|
|
|
useNewPlan: true,
|
2022-06-29 10:19:20 +00:00
|
|
|
planType: TEAM_FREE_PLAN
|
2022-09-29 12:14:10 +00:00
|
|
|
}));
|
(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
2022-03-02 19:07:26 +00:00
|
|
|
}
|
|
|
|
}
|
2022-05-11 19:05:35 +00:00
|
|
|
|
2020-07-21 13:20:51 +00:00
|
|
|
// Launch single-port, self-contained version of Grist.
|
2021-04-02 23:11:27 +00:00
|
|
|
const server = await mergedServerMain(G.port, ["home", "docs", "static"]);
|
|
|
|
if (process.env.GRIST_TESTING_SOCKET) {
|
|
|
|
await server.addTestingHooks();
|
|
|
|
}
|
2022-09-29 12:14:10 +00:00
|
|
|
return server;
|
2020-07-21 13:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
main().catch((err) => console.error(err));
|
|
|
|
}
|