-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (34 loc) · 1.04 KB
/
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
39
const express = require("express");
const { parseDocument, getDocument } = require("./parsing");
const app = express();
/**
* An endpoint returning document data
*
* example document_id: 11wJIGkCKk9GMyOdNlcQMnlJ-7K-VXmb1mA0QsFzG79k
*/
app.get("/", async (req, res) => {
let routes = { "available routes": [] };
app._router.stack.forEach((r) => {
if (r.route && r.route.path) {
routes["available routes"].push(r.route.path);
}
});
res.send(routes);
});
/**
* Actually parsing and reformating the data for our needs
*
* example document_id: 11wJIGkCKk9GMyOdNlcQMnlJ-7K-VXmb1mA0QsFzG79k
*/
app.get("/docs/parse/:document_id", async (req, res) => {
res.send(await parseDocument(req.params.document_id));
});
/**
* An endpoint returning document data
*
* example document_id: 11wJIGkCKk9GMyOdNlcQMnlJ-7K-VXmb1mA0QsFzG79k
*/
app.get("/docs/:document_id", async (req, res) => {
res.send(await getDocument(req.params.document_id));
});
app.listen(1377, (req, res) => console.log("running on port 1377"));