-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
38 lines (30 loc) · 991 Bytes
/
server.js
File metadata and controls
38 lines (30 loc) · 991 Bytes
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
const express = require('express');
const { processPdfByUrl } = require('./processPdfByUrl.js');
var fs = require('fs');
const path = require('path');
const { marked } = require('marked');
const app = express();
const port = process.env.PORT || 3000;
app.use(express.static('public'))
// Display README.md file for server's root
app.get('/', async (req, res, next) => {
var file = fs.readFileSync(path.join(__dirname, '/README.md'), 'utf8');
res.send(marked(file.toString()));
})
app.get('/parser/', async (req, res, next) => {
try {
// Check for query param: pdf
if (!req.query.pdf) {
res.status(400).send('Error: Missing ?pdf= parameter');
return;
}
const pdfUri = req.query.pdf;
const pdfInformation = await processPdfByUrl(pdfUri);
res.send(pdfInformation);
} catch (error) {
next(error);
}
})
app.listen(port, () => {
console.log(`Example app listening on port ${port}`)
})