Move in progress apps temporarily

This commit is contained in:
Darren Clarke 2023-03-07 14:09:49 +00:00
parent ba04aa108c
commit 6eaaf8e9be
360 changed files with 6171 additions and 55 deletions

View file

@ -1,23 +0,0 @@
import { Server } from "@hapi/hapi";
import cloneDeep from "lodash/cloneDeep";
import { deepFreeze } from "../helpers";
interface ConfigOptions {
config: unknown;
}
const register = async (
server: Server,
options: ConfigOptions
): Promise<void> => {
const safeConfig = deepFreeze(cloneDeep(options.config));
server.decorate("server", "config", () => safeConfig);
};
const ConfigPlugin = {
register,
name: "config",
version: "0.0.1",
};
export default ConfigPlugin;

View file

@ -1,37 +0,0 @@
import { Server } from "@hapi/hapi";
import { v4 as uuid } from "uuid";
interface RequestIdOptions {
header?: string;
}
const register = async (
server: Server,
options?: RequestIdOptions
): Promise<void> => {
const header = options?.header || "x-request-id";
server.ext("onPreResponse", async (request, h) => {
if (!request.response) {
return h.continue;
}
if ("isBoom" in request.response) {
const id = request.response.output.headers[header] || uuid();
request.response.output.headers[header] = id;
} else {
const id = request.headers[header] || uuid();
// @ts-ignore
request.response.header(header, id);
}
return h.continue;
});
};
const RequestIdPlugin = {
register,
name: "request-id",
version: "0.0.1",
};
export default RequestIdPlugin;

View file

@ -1,60 +0,0 @@
import { Server, RouteOptionsAccess } from "@hapi/hapi";
import { Prometheus } from "@promster/hapi";
interface StatusOptions {
path?: string;
auth?: RouteOptionsAccess;
}
const count = (statusCounter: any) => async () => {
statusCounter.inc();
return "Incremented metamigo_status_test counter";
};
const ping = async () => "OK";
const statusRoutes = (server: Server, opt?: StatusOptions) => {
const path = opt?.path || "/status";
const statusCounter = new Prometheus.Counter({
name: "metamigo_status_test",
help: "Test counter",
});
return [
{
method: "GET",
path: `${path}/ping`,
handler: ping,
options: {
auth: opt?.auth,
tags: ["api", "status", "ping"],
description: "Returns 200 and OK as the response.",
},
},
{
method: "GET",
path: `${path}/inc`,
handler: count(statusCounter),
options: {
auth: opt?.auth,
tags: ["api", "status", "prometheus"],
description: "Increments a test counter, for testing prometheus.",
},
},
];
};
const register = async (
server: Server,
options: StatusOptions
): Promise<void> => {
server.route(statusRoutes(server, options));
};
const StatusPlugin = {
register,
name: "status",
version: "0.0.1",
};
export default StatusPlugin;