mirror of
https://github.com/gristlabs/grist-core.git
synced 2024-10-27 20:44:07 +00:00
getHostType: consider APP_DOC_INTERNAL_URL as native (#715)
The getHostType() now returns "native" when the host corresponds to the value of APP_DOC_INTERNAL_URL. T While trying to scale, with a different internal and public URL for doc workers, and having configured the org to be specified in the path (GRIST_ORG_IN_PATH=true), the APP_DOC_INTERNAL_URL parameter was not treated as internal which made the connection between home server and doc workers impossible. --------- https://github.com/gristlabs/grist-core/pull/715 Co-authored-by: Florent FAYOLLE <florent.fayolle@beta.gouv.fr>
This commit is contained in:
parent
c8eb1ad4a9
commit
10822d3b86
@ -250,6 +250,7 @@ Variable | Purpose
|
|||||||
-------- | -------
|
-------- | -------
|
||||||
ALLOWED_WEBHOOK_DOMAINS | comma-separated list of permitted domains to use in webhooks (e.g. webhook.site,zapier.com). You can set this to `*` to allow all domains, but if doing so, we recommend using a carefully locked-down proxy (see `GRIST_HTTPS_PROXY`) if you do not entirely trust users. Otherwise services on your internal network may become vulnerable to manipulation.
|
ALLOWED_WEBHOOK_DOMAINS | comma-separated list of permitted domains to use in webhooks (e.g. webhook.site,zapier.com). You can set this to `*` to allow all domains, but if doing so, we recommend using a carefully locked-down proxy (see `GRIST_HTTPS_PROXY`) if you do not entirely trust users. Otherwise services on your internal network may become vulnerable to manipulation.
|
||||||
APP_DOC_URL | doc worker url, set when starting an individual doc worker (other servers will find doc worker urls via redis)
|
APP_DOC_URL | doc worker url, set when starting an individual doc worker (other servers will find doc worker urls via redis)
|
||||||
|
APP_DOC_INTERNAL_URL | like `APP_DOC_URL` but used by the home server to reach the server using an internal domain name resolution (like in a docker environment). Defaults to `APP_DOC_URL`
|
||||||
APP_HOME_URL | url prefix for home api (home and doc servers need this)
|
APP_HOME_URL | url prefix for home api (home and doc servers need this)
|
||||||
APP_STATIC_URL | url prefix for static resources
|
APP_STATIC_URL | url prefix for static resources
|
||||||
APP_STATIC_INCLUDE_CUSTOM_CSS | set to "true" to include custom.css (from APP_STATIC_URL) in static pages
|
APP_STATIC_INCLUDE_CUSTOM_CSS | set to "true" to include custom.css (from APP_STATIC_URL) in static pages
|
||||||
|
@ -167,6 +167,12 @@ export interface OrgUrlInfo {
|
|||||||
orgInPath?: string; // If /o/{orgInPath} should be used to access the requested org.
|
orgInPath?: string; // If /o/{orgInPath} should be used to access the requested org.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function isDocInternalUrl(host: string) {
|
||||||
|
if (!process.env.APP_DOC_INTERNAL_URL) { return false; }
|
||||||
|
const internalUrl = new URL('/', process.env.APP_DOC_INTERNAL_URL);
|
||||||
|
return internalUrl.host === host;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given host (optionally with port), baseDomain, and pluginUrl, determine whether to interpret host
|
* Given host (optionally with port), baseDomain, and pluginUrl, determine whether to interpret host
|
||||||
* as a custom domain, a native domain, or a plugin domain.
|
* as a custom domain, a native domain, or a plugin domain.
|
||||||
@ -184,9 +190,11 @@ export function getHostType(host: string, options: {
|
|||||||
|
|
||||||
const hostname = host.split(":")[0];
|
const hostname = host.split(":")[0];
|
||||||
if (!options.baseDomain) { return 'native'; }
|
if (!options.baseDomain) { return 'native'; }
|
||||||
if (hostname !== 'localhost' && !hostname.endsWith(options.baseDomain)) { return 'custom'; }
|
if (hostname === 'localhost' || isDocInternalUrl(host) || hostname.endsWith(options.baseDomain)) {
|
||||||
return 'native';
|
return 'native';
|
||||||
}
|
}
|
||||||
|
return 'custom';
|
||||||
|
}
|
||||||
|
|
||||||
export function getOrgUrlInfo(newOrg: string, currentHost: string, options: OrgUrlOptions): OrgUrlInfo {
|
export function getOrgUrlInfo(newOrg: string, currentHost: string, options: OrgUrlOptions): OrgUrlInfo {
|
||||||
if (newOrg === options.singleOrg) {
|
if (newOrg === options.singleOrg) {
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import {decodeUrl, IGristUrlState, parseFirstUrlPart} from 'app/common/gristUrls';
|
import {decodeUrl, getHostType, IGristUrlState, parseFirstUrlPart} from 'app/common/gristUrls';
|
||||||
import {assert} from 'chai';
|
import {assert} from 'chai';
|
||||||
|
import * as testUtils from 'test/server/testUtils';
|
||||||
|
|
||||||
describe('gristUrls', function() {
|
describe('gristUrls', function() {
|
||||||
|
|
||||||
@ -76,4 +77,56 @@ describe('gristUrls', function() {
|
|||||||
assert.deepEqual(parseFirstUrlPart('o', ''), {path: ''});
|
assert.deepEqual(parseFirstUrlPart('o', ''), {path: ''});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('getHostType', function() {
|
||||||
|
const defaultOptions = {
|
||||||
|
baseDomain: 'getgrist.com',
|
||||||
|
pluginUrl: 'https://plugin.getgrist.com',
|
||||||
|
};
|
||||||
|
|
||||||
|
let oldEnv: testUtils.EnvironmentSnapshot;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
oldEnv = new testUtils.EnvironmentSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(function () {
|
||||||
|
oldEnv.restore();
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should interpret localhost as "native"', function() {
|
||||||
|
assert.equal(getHostType('localhost', defaultOptions), 'native');
|
||||||
|
assert.equal(getHostType('localhost:8080', defaultOptions), 'native');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should interpret base domain as "native"', function() {
|
||||||
|
assert.equal(getHostType('getgrist.com', defaultOptions), 'native');
|
||||||
|
assert.equal(getHostType('www.getgrist.com', defaultOptions), 'native');
|
||||||
|
assert.equal(getHostType('foo.getgrist.com', defaultOptions), 'native');
|
||||||
|
assert.equal(getHostType('foo.getgrist.com:8080', defaultOptions), 'native');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should interpret plugin domain as "plugin"', function() {
|
||||||
|
assert.equal(getHostType('plugin.getgrist.com', defaultOptions), 'plugin');
|
||||||
|
assert.equal(getHostType('PLUGIN.getgrist.com', { pluginUrl: 'https://pLuGin.getgrist.com' }), 'plugin');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should interpret other domains as "custom"', function() {
|
||||||
|
assert.equal(getHostType('foo.com', defaultOptions), 'custom');
|
||||||
|
assert.equal(getHostType('foo.bar.com', defaultOptions), 'custom');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should interpret doc internal url as "native"', function() {
|
||||||
|
process.env.APP_DOC_INTERNAL_URL = 'https://doc-worker-123.internal/path';
|
||||||
|
assert.equal(getHostType('doc-worker-123.internal', defaultOptions), 'native');
|
||||||
|
assert.equal(getHostType('doc-worker-123.internal:8080', defaultOptions), 'custom');
|
||||||
|
assert.equal(getHostType('doc-worker-124.internal', defaultOptions), 'custom');
|
||||||
|
|
||||||
|
process.env.APP_DOC_INTERNAL_URL = 'https://doc-worker-123.internal:8080/path';
|
||||||
|
assert.equal(getHostType('doc-worker-123.internal:8080', defaultOptions), 'native');
|
||||||
|
assert.equal(getHostType('doc-worker-123.internal', defaultOptions), 'custom');
|
||||||
|
assert.equal(getHostType('doc-worker-124.internal:8080', defaultOptions), 'custom');
|
||||||
|
assert.equal(getHostType('doc-worker-123.internal:8079', defaultOptions), 'custom');
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
@ -17,9 +17,10 @@ describe('DocApi2', function() {
|
|||||||
let owner: UserAPI;
|
let owner: UserAPI;
|
||||||
let wsId: number;
|
let wsId: number;
|
||||||
testUtils.setTmpLogLevel('error');
|
testUtils.setTmpLogLevel('error');
|
||||||
const oldEnv = new testUtils.EnvironmentSnapshot();
|
let oldEnv: testUtils.EnvironmentSnapshot;
|
||||||
|
|
||||||
before(async function() {
|
before(async function() {
|
||||||
|
oldEnv = new testUtils.EnvironmentSnapshot();
|
||||||
const tmpDir = await createTmpDir();
|
const tmpDir = await createTmpDir();
|
||||||
process.env.GRIST_DATA_DIR = tmpDir;
|
process.env.GRIST_DATA_DIR = tmpDir;
|
||||||
process.env.STRIPE_ENDPOINT_SECRET = 'TEST_WITHOUT_ENDPOINT_SECRET';
|
process.env.STRIPE_ENDPOINT_SECRET = 'TEST_WITHOUT_ENDPOINT_SECRET';
|
||||||
|
Loading…
Reference in New Issue
Block a user