beam: stabilize startup model loading
This commit is contained in:
@@ -86,6 +86,11 @@ const sendText = (res, status, message) => {
|
||||
res.end(message);
|
||||
};
|
||||
|
||||
const truncateLogValue = (value, maxLength = 2400) => {
|
||||
const text = typeof value === "string" ? value : JSON.stringify(value);
|
||||
return text.length > maxLength ? `${text.slice(0, maxLength)}…` : text;
|
||||
};
|
||||
|
||||
const setCors = (res) => {
|
||||
res.setHeader("Access-Control-Allow-Origin", "*");
|
||||
res.setHeader("Access-Control-Allow-Methods", "GET,POST,PUT,PATCH,DELETE,OPTIONS");
|
||||
@@ -735,6 +740,9 @@ const handleDeleteProject = async (res, projectId) => {
|
||||
|
||||
const requestHandler = async (req, res) => {
|
||||
const url = new URL(req.url, `http://${req.headers.host || "localhost"}`);
|
||||
if (req.method === "GET" && url.pathname === "/") {
|
||||
console.log("[viewer-request]", truncateLogValue(`${url.pathname}${url.search}`));
|
||||
}
|
||||
|
||||
if (req.method === "OPTIONS") {
|
||||
setCors(res);
|
||||
@@ -743,6 +751,18 @@ const requestHandler = async (req, res) => {
|
||||
return;
|
||||
}
|
||||
|
||||
if (req.method === "POST" && url.pathname === "/api/client-log") {
|
||||
const payload = await parseJSONBody(req);
|
||||
console.log(
|
||||
"[viewer-client]",
|
||||
payload?.level || "info",
|
||||
payload?.event || "event",
|
||||
truncateLogValue(payload || {})
|
||||
);
|
||||
sendJSON(res, 200, {ok: true});
|
||||
return;
|
||||
}
|
||||
|
||||
if (url.pathname.startsWith("/api/projects")) {
|
||||
if (req.method === "GET" && url.pathname === "/api/projects") {
|
||||
return handleGetProjects(res, url.searchParams);
|
||||
|
||||
Reference in New Issue
Block a user