gristlabs_grist-core/test/server/lib/helpers/TestProxyServer.ts
George Gevoian 0cadb93d25 (core) Update dependencies
Summary:
Changes the minimum version of Node to 18, and updates the Docker images and GitHub workflows to build Grist with Node 18.

Also updates various dependencies and scripts to support building running tests with arm64 builds of Node.

Test Plan: Existing tests.

Reviewers: paulfitz

Reviewed By: paulfitz

Differential Revision: https://phab.getgrist.com/D3968
2023-10-11 17:36:58 -04:00

46 lines
1.2 KiB
TypeScript

import {serveSomething, Serving} from "test/server/customUtil";
import * as express from "express";
import axios from "axios";
export class TestProxyServer {
public static async Prepare(portNumber: number): Promise<TestProxyServer> {
const server = new TestProxyServer();
await server._prepare(portNumber);
return server;
}
private _proxyCallsCounter: number = 0;
private _proxyServing: Serving;
private constructor() {
}
public wasProxyCalled(): boolean {
return this._proxyCallsCounter > 0;
}
public async dispose() {
await this._proxyServing.shutdown();
}
private async _prepare(portNumber: number) {
this._proxyServing = await serveSomething(app => {
app.use(express.json());
app.all('*', async (req: express.Request, res: express.Response) => {
this._proxyCallsCounter += 1;
let responseCode;
try {
const axiosResponse = await axios.post(req.url, req.body);
responseCode = axiosResponse.status;
} catch (error: any) {
responseCode = error.response.status;
}
res.sendStatus(responseCode);
res.end();
//next();
});
}, portNumber);
}
}