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
|
|
|
*/
|
|
|
|
|
2023-06-02 08:17:09 +00:00
|
|
|
import {commonUrls} from 'app/common/gristUrls';
|
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');
|
|
|
|
}
|
|
|
|
|
2023-05-20 23:58:41 +00:00
|
|
|
setDefaultEnv('GRIST_UI_FEATURES', 'helpCenter,billing,templates,multiSite,multiAccounts,sendToDrive');
|
2023-06-02 08:17:09 +00:00
|
|
|
setDefaultEnv('GRIST_WIDGET_LIST_URL', commonUrls.gristLabsWidgetRepository);
|
2020-07-21 13:20:51 +00:00
|
|
|
import {updateDb} from 'app/server/lib/dbUtils';
|
2023-09-05 16:05:29 +00:00
|
|
|
import {main as mergedServerMain, parseServerTypes} from 'app/server/mergedServerMain';
|
2020-07-21 13:20:51 +00:00
|
|
|
import * as fse from 'fs-extra';
|
2023-10-24 21:36:53 +00:00
|
|
|
import {runPrometheusExporter} from './prometheus-exporter';
|
2020-07-21 13:20:51 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-09-05 16:05:29 +00:00
|
|
|
async function setupDb() {
|
2020-07-21 13:20:51 +00:00
|
|
|
// Make a blank db if needed.
|
(core) Moving nbrowser tests to grist-core
Summary:
Moving bulk of nbrowser tests to core. Some tests were split and only part of them were moved.
Tests that are left are either: not suitable for grist-core (like billing) or are failing during browser tests (are not reliable).
Four fixtures directory (uploads, docs, exports-csv/excel) where completely moved to grist-core and are linked as folders.
Those changes allows to add an nbrowser test in grist-core or in the main test folder without any need to link it or link a fixture document.
Other changes:
- testrun.sh has been modified, now it runs tests from both folders (test and core/test),
- TestServer used in grist-core is now adding sample orgs and users (kiwi and others),
Test modified
- SelectionSummary: now it is run on a bigScreen, it was failing randomly
- Billing.ts: relative paths were used
- DateEditor: added waitForServer - it was failing in browser mode
- FrozenColumns, ImportFromGDrive, Printing: updated import paths
- UserManager.ts: was split into two parts (it assumed limited products)
- ViewLayoutResize.ts: this test is still in main repo, it is still failing in browser mode tests
Test Plan: Existing
Reviewers: paulfitz
Reviewed By: paulfitz
Subscribers: dsagal, paulfitz
Differential Revision: https://phab.getgrist.com/D3664
2022-10-21 21:34:26 +00:00
|
|
|
if (process.env.TEST_CLEAN_DATABASE) {
|
|
|
|
const {createInitialDb} = require('test/gen-server/seed');
|
|
|
|
await createInitialDb();
|
|
|
|
} else {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2023-09-05 16:05:29 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// tslint:disable:no-console
|
|
|
|
export async function main() {
|
|
|
|
console.log('Welcome to Grist.');
|
|
|
|
if (!debugging) {
|
|
|
|
console.log(`In quiet mode, see http://localhost:${G.port} to use.`);
|
|
|
|
console.log('For full logs, re-run with DEBUG=1');
|
|
|
|
}
|
|
|
|
|
2023-10-24 21:36:53 +00:00
|
|
|
if (process.env.GRIST_PROMCLIENT_PORT) {
|
|
|
|
runPrometheusExporter(parseInt(process.env.GRIST_PROMCLIENT_PORT, 10));
|
|
|
|
}
|
2023-09-05 16:05:29 +00:00
|
|
|
|
|
|
|
// If SAML is not configured, there's no login system, so provide a default email address.
|
|
|
|
setDefaultEnv('GRIST_DEFAULT_EMAIL', 'you@example.com');
|
|
|
|
// Set directory for uploaded documents.
|
|
|
|
setDefaultEnv('GRIST_DATA_DIR', 'docs');
|
|
|
|
setDefaultEnv('GRIST_SERVERS', 'home,docs,static');
|
2023-10-27 19:34:42 +00:00
|
|
|
if (process.env.GRIST_SERVERS?.includes('home')) {
|
|
|
|
// By default, we will now start an untrusted port alongside a
|
|
|
|
// home server, for bundled custom widgets.
|
|
|
|
// Suppress with GRIST_UNTRUSTED_PORT=''
|
|
|
|
setDefaultEnv('GRIST_UNTRUSTED_PORT', '0');
|
|
|
|
}
|
2023-09-05 16:05:29 +00:00
|
|
|
const serverTypes = parseServerTypes(process.env.GRIST_SERVERS);
|
|
|
|
|
|
|
|
await fse.mkdirp(process.env.GRIST_DATA_DIR!);
|
|
|
|
|
|
|
|
if (serverTypes.includes("home")) {
|
|
|
|
console.log('Setting up database...');
|
|
|
|
await setupDb();
|
|
|
|
console.log('Database setup complete.');
|
|
|
|
}
|
2022-05-11 19:05:35 +00:00
|
|
|
|
2020-07-21 13:20:51 +00:00
|
|
|
// Launch single-port, self-contained version of Grist.
|
2023-09-05 16:05:29 +00:00
|
|
|
const server = await mergedServerMain(G.port, serverTypes);
|
2021-04-02 23:11:27 +00:00
|
|
|
if (process.env.GRIST_TESTING_SOCKET) {
|
|
|
|
await server.addTestingHooks();
|
|
|
|
}
|
2023-06-27 06:11:08 +00:00
|
|
|
if (process.env.GRIST_SERVE_PLUGINS_PORT) {
|
|
|
|
await server.startCopy('pluginServer', parseInt(process.env.GRIST_SERVE_PLUGINS_PORT, 10));
|
|
|
|
}
|
2022-09-29 12:14:10 +00:00
|
|
|
return server;
|
2020-07-21 13:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (require.main === module) {
|
2023-07-10 10:24:55 +00:00
|
|
|
main().catch((err) => {
|
|
|
|
console.error(err);
|
|
|
|
});
|
2020-07-21 13:20:51 +00:00
|
|
|
}
|