-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
50 lines (35 loc) · 1.19 KB
/
index.js
File metadata and controls
50 lines (35 loc) · 1.19 KB
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
// Import express and body-parser modules
const express = require('express'),
app = express(),
bodyParser = require('body-parser');
// Load environment variables
require('dotenv').config();
// Configure express app to use bodyParser middleware
app.use(bodyParser.json());
// Import route handler modules
const load = require('./src/process/ingest');
const ask = require('./src/process/ask');
// Set port from environment or default
const port = 3000 | process.env.PORT;
// POST route handler for file loading
app.post('/load', async (req, res) => {
// Call ingestion handler
const loadFile = await load.load(req.body);
// Set response headers
res.setHeader('Content-Type', 'application/json');
// Send back response
res.end(JSON.stringify(loadFile));
});
// POST route handler for asking questions
app.post('/ask', async (req, res) => {
// Call ask handler
const askResponse = await ask.ask(req.body);
// Set response headers
res.setHeader('Content-Type', 'application/json');
// Send back response
res.end(JSON.stringify(askResponse));
});
// Start express server
app.listen(port, () => {
console.log(`answerPDF running on http://localhost:${port}`)
});