feat(feature-control): add standalone BFF with bootstrap, exposure telemetry and tests
This commit is contained in:
34
feature-control-bff/server.mjs
Normal file
34
feature-control-bff/server.mjs
Normal file
@@ -0,0 +1,34 @@
|
||||
import http from "node:http";
|
||||
import { createRuntime, handleBootstrap, handleExposure, loadConfig, nowIso, writeJson } from "./core.mjs";
|
||||
|
||||
const PORT = Number(process.env.PORT || 8787);
|
||||
const runtime = createRuntime(loadConfig(process.env));
|
||||
|
||||
const server = http.createServer(async (req, res) => {
|
||||
const method = req.method || "GET";
|
||||
const url = req.url || "/";
|
||||
|
||||
if (method === "GET" && url === "/health") {
|
||||
return writeJson(res, 200, {
|
||||
ok: true,
|
||||
service: "feature-control-bff",
|
||||
time: nowIso(),
|
||||
cacheEntries: runtime.cache.size,
|
||||
inFlight: runtime.inFlight.size
|
||||
});
|
||||
}
|
||||
|
||||
if (method === "POST" && url === "/feature-control/bootstrap") {
|
||||
return handleBootstrap(req, res, runtime);
|
||||
}
|
||||
|
||||
if (method === "POST" && url === "/feature-control/telemetry/exposure") {
|
||||
return handleExposure(req, res, runtime);
|
||||
}
|
||||
|
||||
return writeJson(res, 404, { ok: false, code: "NOT_FOUND", message: "Rota não encontrada" });
|
||||
});
|
||||
|
||||
server.listen(PORT, () => {
|
||||
console.log(`[feature-control-bff] listening on :${PORT}`);
|
||||
});
|
||||
Reference in New Issue
Block a user