From cff02cd3d07ad1cd4b1087675894e868df9cf74d Mon Sep 17 00:00:00 2001 From: Paul Fitzpatrick Date: Thu, 24 Sep 2020 10:34:44 -0400 Subject: [PATCH] (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 --- README.md | 14 +++++++++++--- stubs/app/server/server.ts | 22 ++++++++++++++++------ 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index eee188bd..1d59dfb5 100644 --- a/README.md +++ b/README.md @@ -45,12 +45,20 @@ For building from source, you can start with this: npm install npm run build:prod npm run install:python - GRIST_DEFAULT_EMAIL=you@example.com npm start + npm start # unauthenticated grist api available at http://localhost:8484/api/ -Stay tuned for more instructions to come at release. +Then you can use the Grist API locally to work on a document. Currently you need +to "upload" a document to work with it. This makes a copy of it that the server +controls - you can find it in the `data` directory: -For using pre-built Grist, just head on over to . + curl -F 'upload=@YourDocument.grist' http://localhost:8484/api/docs + # Note the document ID that is returned. + +The [Data-Tables endpoints](https://support.getgrist.com/api/#tag/Data-Tables) are +particularly useful. + +For using hosted Grist, just head on over to . # License diff --git a/stubs/app/server/server.ts b/stubs/app/server/server.ts index 7faa8e43..80a513a7 100644 --- a/stubs/app/server/server.ts +++ b/stubs/app/server/server.ts @@ -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)); }