-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
33 lines (26 loc) · 919 Bytes
/
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
'use strict';
const express = require('express');
const util = require("util");
const exec = util.promisify(require("child_process").exec);
const cors = require('cors')
// Constants
const PORT = 8080;
const HOST = '0.0.0.0';
const formatResponse = (output) => `<html><body><pre><code>${output}</code></pre></body></html>`;
// App
const app = express();
app.use(cors({credentials: true, origin: true}))
app.get('/verify', async (req, res) => {
if (!req.query.url) return res.send("provide a url param");
console.log(req.query.url);
await exec(`curl ${req.query.url} -o file.asice`);
try {
const result = await exec('/usr/local/bin/digidoc-tool open file.asice')
res.send(formatResponse(result.stdout));
} catch(e) {
res.send(formatResponse(e.message));
}
await exec(`rm file.asice`);
});
app.listen(PORT, HOST);
console.log(`Running on http://${HOST}:${PORT}`);