-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
71 lines (60 loc) · 1.87 KB
/
server.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import express from "express";
import cors from "cors";
import dotenv from "dotenv";
import { megaSearch } from "./mega-search/mega-search.js";
import { getFlashcards } from "./flashcards/flashcards.js";
import { reporterAPIHandler } from "./reporter-input-response/reporter-API-handler.js";
import { reporterStreamHandler } from "./reporter-input-response/reporter-stream-handler.js";
const app = express();
app.use(cors());
app.use(express.json());
dotenv.config();
app.get("/express", (req, res) => {
console.log("get call to /express");
res.send("q72 express server is running");
});
app.post("/test", async (req, res) => {
console.log("post call to /test");
console.log(req.body);
res.json({ message: "hello from /test" });
});
app.post("/mega-search", async (req, res) => {
console.log(req.body);
const output = await megaSearch(req.body.message);
res.json({ message: output });
});
app.post("/flashcards/v2", async (req, res) => {
const responseData = {
message: "v2 flashcards",
cardSets: await getFlashcards("v2"),
};
res.json(responseData);
});
app.post("/flashcards/v1", async (req, res) => {
const clientCode = req.body.code;
console.log(clientCode);
if (clientCode === "g") {
const responseData = {
message: "Access code accepted",
cardSets: await getFlashcards("v1"),
};
res.json(responseData);
} else {
res.status(401).send("Unauthorized");
}
});
app.post("/reporter/stream", async (req, res) => {
console.log("post call to /reporter/stream");
console.log(req.body);
reporterStreamHandler(req, res);
});
app.post("/reporter", async (req, res) => {
console.log("post call to /reporter");
console.log(req.body);
var response = await reporterAPIHandler(req.body);
res.json(response);
});
const PORT = process.env.PORT || 3000;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});