(core) simplify starting grist-core and add some more usage information

Summary:
I worked through the README for grist-core, and the instructions
for setting it up and starting it.  This change includes a small
simplification, and a few more instructions for getting started.

Test Plan: manual

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D2619
This commit is contained in:
Paul Fitzpatrick
2020-09-24 10:34:44 -04:00
parent a15187362c
commit cff02cd3d0
2 changed files with 27 additions and 9 deletions

View File

@@ -1,5 +1,7 @@
/**
* Main entrypoint for grist-core server.
*
* By default, starts up on port 8484.
*/
import {updateDb} from 'app/server/lib/dbUtils';
@@ -10,20 +12,28 @@ const G = {
port: parseInt(process.env.PORT!, 10) || 8484,
};
// Set a default for an environment variable.
function setDefaultEnv(name: string, value: string) {
if (process.env[name] === undefined) {
process.env[name] = value;
}
}
export async function main() {
// Use a distinct cookie.
if (!process.env.GRIST_SESSION_COOKIE) {
process.env.GRIST_SESSION_COOKIE = 'grist_core';
}
// This is where documents are placed, for historic reasons.
await fse.mkdirp('samples');
setDefaultEnv('GRIST_SESSION_COOKIE', 'grist_core');
// There's no login system released yet, so set a default email address.
setDefaultEnv('GRIST_DEFAULT_EMAIL', 'support@getgrist.com');
// Set directory for uploaded documents.
setDefaultEnv('GRIST_DATA_DIR', 'data');
await fse.mkdirp(process.env.GRIST_DATA_DIR!);
// Make a blank db if needed.
await updateDb();
// Launch single-port, self-contained version of Grist.
// You probably want to have GRIST_DEFAULT_EMAIL set since there's no login system yet.
await mergedServerMain(G.port, ["home", "docs", "static"]);
}
if (require.main === module) {
// tslint:disable-next-line:no-console
main().catch((err) => console.error(err));
}