Skip to content

Commit

Permalink
move vector db debug endpoint to dev only
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycarambat committed Mar 27, 2024
1 parent 99cfee1 commit bf8df60
Showing 1 changed file with 29 additions and 28 deletions.
57 changes: 29 additions & 28 deletions server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,34 +51,6 @@ developerEndpoints(app, apiRouter);
// Externally facing embedder endpoints
embeddedEndpoints(apiRouter);

apiRouter.post("/v/:command", async (request, response) => {
try {
const VectorDb = getVectorDbClass();
const { command } = request.params;
if (!Object.getOwnPropertyNames(VectorDb).includes(command)) {
response.status(500).json({
message: "invalid interface command",
commands: Object.getOwnPropertyNames(VectorDb),
});
return;
}

try {
const body = reqBody(request);
const resBody = await VectorDb[command](body);
response.status(200).json({ ...resBody });
} catch (e) {
// console.error(e)
console.error(JSON.stringify(e));
response.status(500).json({ error: e.message });
}
return;
} catch (e) {
console.log(e.message, e);
response.sendStatus(500).end();
}
});

if (process.env.NODE_ENV !== "development") {
app.use(
express.static(path.resolve(__dirname, "public"), { extensions: ["js"] })
Expand All @@ -92,6 +64,35 @@ if (process.env.NODE_ENV !== "development") {
response.type("text/plain");
response.send("User-agent: *\nDisallow: /").end();
});
} else {
// Debug route for development connections to vectorDBs
apiRouter.post("/v/:command", async (request, response) => {
try {
const VectorDb = getVectorDbClass();
const { command } = request.params;
if (!Object.getOwnPropertyNames(VectorDb).includes(command)) {
response.status(500).json({
message: "invalid interface command",
commands: Object.getOwnPropertyNames(VectorDb),
});
return;
}

try {
const body = reqBody(request);
const resBody = await VectorDb[command](body);
response.status(200).json({ ...resBody });
} catch (e) {
// console.error(e)
console.error(JSON.stringify(e));
response.status(500).json({ error: e.message });
}
return;
} catch (e) {
console.log(e.message, e);
response.sendStatus(500).end();
}
});
}

app.all("*", function (_, response) {
Expand Down

0 comments on commit bf8df60

Please sign in to comment.