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';
|
|
|
|
|
|
|
|
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
|
|
|
|
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.
|
2021-08-16 15:11:17 +00:00
|
|
|
if (!process.env.GRIST_SAML_SP_HOST) {
|
|
|
|
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();
|
|
|
|
// 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();
|
|
|
|
}
|
2020-07-21 13:20:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (require.main === module) {
|
|
|
|
main().catch((err) => console.error(err));
|
|
|
|
}
|