21 lines
888 B
JavaScript
21 lines
888 B
JavaScript
#!/usr/bin/env node
|
|
import { createMvpTopology } from "../../internal/patchpanel/fixture.mjs";
|
|
import { createPatchPanel } from "../../internal/patchpanel/model.mjs";
|
|
import { createHealth } from "../../internal/sim/model.mjs";
|
|
import { createJsonServer, listen, parsePort, readJson } from "../../internal/sim/http.mjs";
|
|
|
|
const port = parsePort(process.env.PORT, 7301);
|
|
const topology = createMvpTopology();
|
|
const patchPanel = createPatchPanel({ wiringConfig: topology.wiringConfig });
|
|
|
|
const routes = new Map();
|
|
|
|
routes.set("GET /health/live", () =>
|
|
createHealth({ serviceId: "hwlab-patch-panel", name: "hwlab-patch-panel" })
|
|
);
|
|
routes.set("GET /status", () => patchPanel.status());
|
|
routes.set("GET /wiring", () => patchPanel.wiringConfig);
|
|
routes.set("POST /signals/route", async ({ req }) => patchPanel.routeSignal(await readJson(req)));
|
|
|
|
listen(createJsonServer({ routes }), port);
|