mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-09-28 20:50:45 +00:00
54beaede84
Summary: SAML support had broken due to SameSite changes in browsers. This makes it work again, and tests it against Auth0 (now owned by Okta). Logging in and out works. The logged out state is confusing, and may not be complete. The "Add Account" menu item doesn't work. But with this, an important part of self-hosting becomes easier. SAML support works also in grist-core, for site pages, but there is a glitch on document pages that I'll look into separately. Test Plan: tested manually Reviewers: dsagal Reviewed By: dsagal Differential Revision: https://phab.getgrist.com/D2976
63 lines
1.8 KiB
TypeScript
63 lines
1.8 KiB
TypeScript
/**
|
|
* Main entrypoint for grist-core server.
|
|
*
|
|
* By default, starts up on port 8484.
|
|
*/
|
|
|
|
import {isAffirmative} from 'app/common/gutil';
|
|
|
|
const debugging = isAffirmative(process.env.DEBUG) || isAffirmative(process.env.VERBOSE);
|
|
|
|
// Set log levels before importing anything.
|
|
if (!debugging) {
|
|
// Be a lot less noisy by default.
|
|
setDefaultEnv('GRIST_LOG_LEVEL', 'error');
|
|
setDefaultEnv('GRIST_LOG_SKIP_HTTP', 'true');
|
|
}
|
|
|
|
// Use a distinct cookie.
|
|
setDefaultEnv('GRIST_SESSION_COOKIE', 'grist_core');
|
|
|
|
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,
|
|
};
|
|
|
|
// Set a default for an environment variable.
|
|
function setDefaultEnv(name: string, value: string) {
|
|
if (process.env[name] === undefined) {
|
|
process.env[name] = value;
|
|
}
|
|
}
|
|
|
|
// 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');
|
|
}
|
|
|
|
// If SAML is not configured, there's no login system, so force a default email address.
|
|
if (!process.env.GRIST_SAML_SP_HOST) {
|
|
setDefaultEnv('GRIST_DEFAULT_EMAIL', 'you@example.com');
|
|
}
|
|
// Set directory for uploaded documents.
|
|
setDefaultEnv('GRIST_DATA_DIR', 'docs');
|
|
await fse.mkdirp(process.env.GRIST_DATA_DIR!);
|
|
// Make a blank db if needed.
|
|
await updateDb();
|
|
// Launch single-port, self-contained version of Grist.
|
|
const server = await mergedServerMain(G.port, ["home", "docs", "static"]);
|
|
if (process.env.GRIST_TESTING_SOCKET) {
|
|
await server.addTestingHooks();
|
|
}
|
|
}
|
|
|
|
if (require.main === module) {
|
|
main().catch((err) => console.error(err));
|
|
}
|