Skip to content

Commit

Permalink
Rename TestServerProxy to TestServerReverseProxy
Browse files Browse the repository at this point in the history
  • Loading branch information
fflorent committed May 7, 2024
1 parent 55a26c0 commit 14b2bfa
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 13 deletions.
8 changes: 4 additions & 4 deletions test/server/lib/DocApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import {serveSomething, Serving} from 'test/server/customUtil';
import {prepareDatabase} from 'test/server/lib/helpers/PrepareDatabase';
import {prepareFilesystemDirectoryForTests} from 'test/server/lib/helpers/PrepareFilesystemDirectoryForTests';
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 {waitForIt} from 'test/server/wait';
import defaultsDeep = require('lodash/defaultsDeep');
Expand Down Expand Up @@ -155,8 +155,8 @@ describe('DocApi', function () {
testDocApi();
});

describe("should work behind a proxy", async () => {
let proxy: TestServerProxy;
describe("should work behind a reverse-proxy", async () => {
let proxy: TestServerReverseProxy;

const originalHeaders = new WeakMap<AxiosRequestConfig, AxiosRequestConfig["headers"]>();
function iterateOverAccountHeaders (
Expand All @@ -169,7 +169,7 @@ describe('DocApi', function () {
}
}
setup('behind-proxy', async () => {
proxy = new TestServerProxy();
proxy = new TestServerReverseProxy();
const additionalEnvConfiguration = {
ALLOWED_WEBHOOK_DOMAINS: `example.com,localhost:${webhooksTestPort}`,
GRIST_DATA_DIR: dataDir,
Expand Down
2 changes: 0 additions & 2 deletions test/server/lib/helpers/TestProxyServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ export class TestProxyServer {
const server = new TestProxyServer();
await server._prepare(portNumber);
return server;

}

private _proxyCallsCounter: number = 0;
Expand Down Expand Up @@ -38,7 +37,6 @@ export class TestProxyServer {
}
res.sendStatus(responseCode);
res.end();
//next();
});
}, portNumber);
}
Expand Down
11 changes: 4 additions & 7 deletions test/server/lib/helpers/TestServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,21 +197,19 @@ export class TestServer {
}
}

// FIXME: found that TestProxyServer exist, what should I do? :'(
export class TestServerProxy {
export class TestServerReverseProxy {

// 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();
private _server: http.Server;
private _address: Promise<AddressInfo>;

public get stopped() { return this._stopped; }
public get stopped() { return !this._server.listening; }

public constructor() {
this._address = new Promise(resolve => {
Expand All @@ -236,15 +234,14 @@ export class TestServerProxy {

public async getServerUrl() {
const address = await this.getAddress();
return `http://${TestServerProxy.HOSTNAME}:${address.port}`;
return `http://${TestServerReverseProxy.HOSTNAME}:${address.port}`;
}

public stop() {
if (this._stopped) {
if (this.stopped) {
return;
}
log.info("Stopping node TestServerProxy");
this._stopped = true;
this._server.close();
}

Expand Down

0 comments on commit 14b2bfa

Please sign in to comment.