-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
38 lines (32 loc) · 861 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import express from "express";
import path from "path";
import cors from "cors";
import { chain } from "./example_scripts/scram-into-single-question";
const app = express();
const port = 3000;
app.use(express.json());
app.use(cors());
app.use(express.static("public"));
app.get("/", function (req, res) {
try {
res.sendFile("public/index.html");
res.status(200);
} catch (error) {
console.debug("Something", error);
res.status(500);
}
});
app.post("/question", async function (req, res) {
try {
const answer = await chain.invoke({ question: req.body.question });
res.json({ answer: answer });
res.status(200);
res.end();
} catch (error) {
console.error("The error deatils we know:", error);
res.status(500);
}
});
app.listen(port, function () {
console.info(`Web Server is listening at ${port}`);
});