Use nip.io to have a specific hostname for proxy

Also use GRIST_ORG_IN_PATH to make it work as expected, and
GRIST_SINGLE_PORT=0 to ensure to query the pool of workers.
pull/915/head
fflorent 3 weeks ago
parent ac2857cd85
commit 47c8804a01

@ -173,12 +173,14 @@ describe('DocApi', function () {
const additionalEnvConfiguration = {
ALLOWED_WEBHOOK_DOMAINS: `example.com,localhost:${webhooksTestPort}`,
GRIST_DATA_DIR: dataDir,
APP_HOME_URL: await proxy.getServerUrl()
APP_HOME_URL: await proxy.getServerUrl(),
GRIST_ORG_IN_PATH: 'true',
GRIST_SINGLE_PORT: '0',
};
home = await TestServer.startServer('home', tmpDir, suitename, additionalEnvConfiguration);
docs = await TestServer.startServer('docs', tmpDir, suitename, additionalEnvConfiguration, home.serverUrl);
proxy.start(home, docs);
await proxy.start(home, docs);
homeUrl = serverUrl = await proxy.getServerUrl();
iterateOverAccountHeaders(account => {
@ -3182,8 +3184,9 @@ function testDocApi() {
it("GET /docs/{did1}/compare/{did2} tracks changes between docs", async function () {
// Pass kiwi's headers as it contains both Authorization and Origin headers
// if run behind a proxy, so we can ensure that the Origin header check is not made.
const userApiServerUrl = docs.proxiedServer ? serverUrl : undefined;
const chimpyApi = home.makeUserApi(
ORG_NAME, 'chimpy', { serverUrl, headers: chimpy.headers as Record<string, string> }
ORG_NAME, 'chimpy', { serverUrl: userApiServerUrl, headers: chimpy.headers as Record<string, string> }
);
const ws1 = (await chimpyApi.getOrgWorkspaces('current'))[0].id;
const docId1 = await chimpyApi.newDoc({name: 'testdoc1'}, ws1);

@ -199,7 +199,12 @@ export class TestServer {
// FIXME: found that TestProxyServer exist, what should I do? :'(
export class TestServerProxy {
public static readonly HOSTNAME: string = 'grist-test-proxy.localhost';
// Use a different hostname for the proxy than the doc and home workers'
// so we can ensure that either we omit the Origin header (so the internal calls to home and doc workers
// are not considered as CORS requests), or otherwise we fail because the hostnames are different
// https://github.com/gristlabs/grist-core/blob/24b39c651b9590cc360cc91b587d3e1b301a9c63/app/server/lib/requestUtils.ts#L85-L98
public static readonly HOSTNAME: string = 'grist-test-proxy.127.0.0.1.nip.io';
private _stopped: boolean = false;
private _app = express();
@ -210,18 +215,19 @@ export class TestServerProxy {
public constructor() {
this._address = new Promise(resolve => {
this._server = this._app.listen(0, TestServerProxy.HOSTNAME, () => {
this._server = this._app.listen(0, () => {
resolve(this._server.address() as AddressInfo);
});
});
}
public start(homeServer: TestServer, docServer: TestServer) {
public async start(homeServer: TestServer, docServer: TestServer) {
this._app.all(['/dw/dw1', '/dw/dw1/*'], (oreq, ores) => this._getRequestHandlerFor(docServer));
this._app.all('/*', this._getRequestHandlerFor(homeServer));
// Forbid now the use of serverUrl property
homeServer.disallowDirectAccess();
docServer.disallowDirectAccess();
log.info('proxy server running on ', await this.getServerUrl());
}
public async getAddress() {
@ -254,11 +260,11 @@ export class TestServerProxy {
headers: oreq.headers,
};
log.debug('[proxy] Requesting: ' + oreq.url);
log.debug(`[proxy] Requesting (method=${oreq.method}): ${new URL(oreq.url, serverUrl).href}`);
const creq = http
.request(options, pres => {
log.debug('[proxy] Received response for ' + pres.url);
log.debug('[proxy] Received response for ' + oreq.url);
// set encoding, required?
pres.setEncoding('utf8');

Loading…
Cancel
Save