Rename TestServerProxy to TestServerReverseProxy

pull/915/head
fflorent 1 month ago
parent 55a26c05fc
commit 14b2bfa2ba

@ -35,7 +35,7 @@ import {serveSomething, Serving} from 'test/server/customUtil';
import {prepareDatabase} from 'test/server/lib/helpers/PrepareDatabase'; import {prepareDatabase} from 'test/server/lib/helpers/PrepareDatabase';
import {prepareFilesystemDirectoryForTests} from 'test/server/lib/helpers/PrepareFilesystemDirectoryForTests'; import {prepareFilesystemDirectoryForTests} from 'test/server/lib/helpers/PrepareFilesystemDirectoryForTests';
import {signal} from 'test/server/lib/helpers/Signal'; import {signal} from 'test/server/lib/helpers/Signal';
import {TestServer, TestServerProxy} from 'test/server/lib/helpers/TestServer'; import {TestServer, TestServerReverseProxy} from 'test/server/lib/helpers/TestServer';
import * as testUtils from 'test/server/testUtils'; import * as testUtils from 'test/server/testUtils';
import {waitForIt} from 'test/server/wait'; import {waitForIt} from 'test/server/wait';
import defaultsDeep = require('lodash/defaultsDeep'); import defaultsDeep = require('lodash/defaultsDeep');
@ -155,8 +155,8 @@ describe('DocApi', function () {
testDocApi(); testDocApi();
}); });
describe("should work behind a proxy", async () => { describe("should work behind a reverse-proxy", async () => {
let proxy: TestServerProxy; let proxy: TestServerReverseProxy;
const originalHeaders = new WeakMap<AxiosRequestConfig, AxiosRequestConfig["headers"]>(); const originalHeaders = new WeakMap<AxiosRequestConfig, AxiosRequestConfig["headers"]>();
function iterateOverAccountHeaders ( function iterateOverAccountHeaders (
@ -169,7 +169,7 @@ describe('DocApi', function () {
} }
} }
setup('behind-proxy', async () => { setup('behind-proxy', async () => {
proxy = new TestServerProxy(); proxy = new TestServerReverseProxy();
const additionalEnvConfiguration = { const additionalEnvConfiguration = {
ALLOWED_WEBHOOK_DOMAINS: `example.com,localhost:${webhooksTestPort}`, ALLOWED_WEBHOOK_DOMAINS: `example.com,localhost:${webhooksTestPort}`,
GRIST_DATA_DIR: dataDir, GRIST_DATA_DIR: dataDir,

@ -7,7 +7,6 @@ export class TestProxyServer {
const server = new TestProxyServer(); const server = new TestProxyServer();
await server._prepare(portNumber); await server._prepare(portNumber);
return server; return server;
} }
private _proxyCallsCounter: number = 0; private _proxyCallsCounter: number = 0;
@ -38,7 +37,6 @@ export class TestProxyServer {
} }
res.sendStatus(responseCode); res.sendStatus(responseCode);
res.end(); res.end();
//next();
}); });
}, portNumber); }, portNumber);
} }

@ -197,8 +197,7 @@ export class TestServer {
} }
} }
// FIXME: found that TestProxyServer exist, what should I do? :'( export class TestServerReverseProxy {
export class TestServerProxy {
// Use a different hostname for the proxy than the doc and home workers' // 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 // so we can ensure that either we omit the Origin header (so the internal calls to home and doc workers
@ -206,12 +205,11 @@ export class TestServerProxy {
// https://github.com/gristlabs/grist-core/blob/24b39c651b9590cc360cc91b587d3e1b301a9c63/app/server/lib/requestUtils.ts#L85-L98 // 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'; public static readonly HOSTNAME: string = 'grist-test-proxy.127.0.0.1.nip.io';
private _stopped: boolean = false;
private _app = express(); private _app = express();
private _server: http.Server; private _server: http.Server;
private _address: Promise<AddressInfo>; private _address: Promise<AddressInfo>;
public get stopped() { return this._stopped; } public get stopped() { return !this._server.listening; }
public constructor() { public constructor() {
this._address = new Promise(resolve => { this._address = new Promise(resolve => {
@ -236,15 +234,14 @@ export class TestServerProxy {
public async getServerUrl() { public async getServerUrl() {
const address = await this.getAddress(); const address = await this.getAddress();
return `http://${TestServerProxy.HOSTNAME}:${address.port}`; return `http://${TestServerReverseProxy.HOSTNAME}:${address.port}`;
} }
public stop() { public stop() {
if (this._stopped) { if (this.stopped) {
return; return;
} }
log.info("Stopping node TestServerProxy"); log.info("Stopping node TestServerProxy");
this._stopped = true;
this._server.close(); this._server.close();
} }

Loading…
Cancel
Save