mirror of
https://github.com/monkeytypegame/monkeytype.git
synced 2025-10-03 04:00:41 +08:00
impr(dev): add configurable server response slowdown
This commit is contained in:
parent
da7e59a28a
commit
1686287f93
3 changed files with 27 additions and 5 deletions
|
@ -25,6 +25,8 @@ import {
|
|||
static as expressStatic,
|
||||
} from "express";
|
||||
import { isDevEnvironment } from "../../utils/misc";
|
||||
import { getLiveConfiguration } from "../../init/configuration";
|
||||
import Logger from "../../utils/logger";
|
||||
|
||||
const pathOverride = process.env["API_PATH_OVERRIDE"];
|
||||
const BASE_ROUTE = pathOverride !== undefined ? `/${pathOverride}` : "";
|
||||
|
@ -57,11 +59,14 @@ function addApiRoutes(app: Application): void {
|
|||
});
|
||||
app.use("/configure", expressStatic(join(__dirname, "../../../private")));
|
||||
|
||||
//simulate delay for all requests
|
||||
// app.use(async (req, res, next) => {
|
||||
// await new Promise((resolve) => setTimeout(resolve, 1000));
|
||||
// next();
|
||||
// });
|
||||
app.use(async (req, res, next) => {
|
||||
const slowdown = (await getLiveConfiguration()).dev.responseSlowdownMs;
|
||||
if (slowdown > 0) {
|
||||
Logger.info(`Simulating ${slowdown}ms delay for ${req.path}`);
|
||||
await new Promise((resolve) => setTimeout(resolve, slowdown));
|
||||
}
|
||||
next();
|
||||
});
|
||||
}
|
||||
|
||||
// Cannot be added to the route map because it needs to be added before the maintenance handler
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
*/
|
||||
export const BASE_CONFIGURATION: SharedTypes.Configuration = {
|
||||
maintenance: false,
|
||||
dev: {
|
||||
responseSlowdownMs: 0,
|
||||
},
|
||||
results: {
|
||||
savingEnabled: false,
|
||||
objectHashCheckEnabled: false,
|
||||
|
@ -151,6 +154,17 @@ export const CONFIGURATION_FORM_SCHEMA: ObjectSchema<SharedTypes.Configuration>
|
|||
type: "boolean",
|
||||
label: "In Maintenance",
|
||||
},
|
||||
dev: {
|
||||
type: "object",
|
||||
label: "Development",
|
||||
fields: {
|
||||
responseSlowdownMs: {
|
||||
type: "number",
|
||||
label: "Response Slowdown (miliseconds)",
|
||||
min: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
results: {
|
||||
type: "object",
|
||||
label: "Results",
|
||||
|
|
3
shared-types/types.d.ts
vendored
3
shared-types/types.d.ts
vendored
|
@ -14,6 +14,9 @@ declare namespace SharedTypes {
|
|||
|
||||
interface Configuration {
|
||||
maintenance: boolean;
|
||||
dev: {
|
||||
responseSlowdownMs: number;
|
||||
};
|
||||
quotes: {
|
||||
reporting: {
|
||||
enabled: boolean;
|
||||
|
|
Loading…
Add table
Reference in a new issue