mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
Make server take into account GRIST_SERVERS (#659)
Also ensure that only a home server will setup the database. resolves #654 Co-authored-by: Florent FAYOLLE <florent.fayolle@beta.gouv.fr>
This commit is contained in:
parent
6dab12f301
commit
1ac15912b1
@ -282,6 +282,7 @@ GRIST_PAGE_TITLE_SUFFIX | a string to append to the end of the `<title>` in HTML
|
|||||||
GRIST_PROXY_AUTH_HEADER | header which will be set by a (reverse) proxy webserver with an authorized users' email. This can be used as an alternative to a SAML service. See also GRIST_FORWARD_AUTH_HEADER.
|
GRIST_PROXY_AUTH_HEADER | header which will be set by a (reverse) proxy webserver with an authorized users' email. This can be used as an alternative to a SAML service. See also GRIST_FORWARD_AUTH_HEADER.
|
||||||
GRIST_ROUTER_URL | optional url for an api that allows servers to be (un)registered with a load balancer
|
GRIST_ROUTER_URL | optional url for an api that allows servers to be (un)registered with a load balancer
|
||||||
GRIST_SERVE_SAME_ORIGIN | set to "true" to access home server and doc workers on the same protocol-host-port as the top-level page, same as for custom domains (careful, host header should be trustworthy)
|
GRIST_SERVE_SAME_ORIGIN | set to "true" to access home server and doc workers on the same protocol-host-port as the top-level page, same as for custom domains (careful, host header should be trustworthy)
|
||||||
|
GRIST_SERVERS | the types of server to setup. Comma separated values which may contain "home", "docs", static" and/or "app". Defaults to "home,docs,static".
|
||||||
GRIST_SESSION_COOKIE | if set, overrides the name of Grist's cookie
|
GRIST_SESSION_COOKIE | if set, overrides the name of Grist's cookie
|
||||||
GRIST_SESSION_DOMAIN | if set, associates the cookie with the given domain - otherwise defaults to GRIST_DOMAIN
|
GRIST_SESSION_DOMAIN | if set, associates the cookie with the given domain - otherwise defaults to GRIST_DOMAIN
|
||||||
GRIST_SESSION_SECRET | a key used to encode sessions
|
GRIST_SESSION_SECRET | a key used to encode sessions
|
||||||
|
@ -15,7 +15,7 @@ export type ServerType = "home" | "docs" | "static" | "app";
|
|||||||
const allServerTypes: ServerType[] = ["home", "docs", "static", "app"];
|
const allServerTypes: ServerType[] = ["home", "docs", "static", "app"];
|
||||||
|
|
||||||
// Parse a comma-separate list of server types into an array, with validation.
|
// Parse a comma-separate list of server types into an array, with validation.
|
||||||
function parseServerTypes(serverTypes: string|undefined): ServerType[] {
|
export function parseServerTypes(serverTypes: string|undefined): ServerType[] {
|
||||||
// Split and filter out empty strings (including the one we get when splitting "").
|
// Split and filter out empty strings (including the one we get when splitting "").
|
||||||
const types = (serverTypes || "").trim().split(',').filter(part => Boolean(part));
|
const types = (serverTypes || "").trim().split(',').filter(part => Boolean(part));
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ if (!process.env.GRIST_SINGLE_ORG) {
|
|||||||
setDefaultEnv('GRIST_UI_FEATURES', 'helpCenter,billing,templates,multiSite,multiAccounts,sendToDrive');
|
setDefaultEnv('GRIST_UI_FEATURES', 'helpCenter,billing,templates,multiSite,multiAccounts,sendToDrive');
|
||||||
setDefaultEnv('GRIST_WIDGET_LIST_URL', commonUrls.gristLabsWidgetRepository);
|
setDefaultEnv('GRIST_WIDGET_LIST_URL', commonUrls.gristLabsWidgetRepository);
|
||||||
import {updateDb} from 'app/server/lib/dbUtils';
|
import {updateDb} from 'app/server/lib/dbUtils';
|
||||||
import {main as mergedServerMain} from 'app/server/mergedServerMain';
|
import {main as mergedServerMain, parseServerTypes} from 'app/server/mergedServerMain';
|
||||||
import * as fse from 'fs-extra';
|
import * as fse from 'fs-extra';
|
||||||
|
|
||||||
const G = {
|
const G = {
|
||||||
@ -48,19 +48,7 @@ function setDefaultEnv(name: string, value: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// tslint:disable:no-console
|
async function setupDb() {
|
||||||
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 provide a default email address.
|
|
||||||
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.
|
// Make a blank db if needed.
|
||||||
if (process.env.TEST_CLEAN_DATABASE) {
|
if (process.env.TEST_CLEAN_DATABASE) {
|
||||||
const {createInitialDb} = require('test/gen-server/seed');
|
const {createInitialDb} = require('test/gen-server/seed');
|
||||||
@ -104,9 +92,33 @@ export async function main() {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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 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');
|
||||||
|
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.');
|
||||||
|
}
|
||||||
|
|
||||||
// Launch single-port, self-contained version of Grist.
|
// Launch single-port, self-contained version of Grist.
|
||||||
const server = await mergedServerMain(G.port, ["home", "docs", "static"]);
|
const server = await mergedServerMain(G.port, serverTypes);
|
||||||
if (process.env.GRIST_TESTING_SOCKET) {
|
if (process.env.GRIST_TESTING_SOCKET) {
|
||||||
await server.addTestingHooks();
|
await server.addTestingHooks();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user