-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
47 lines (38 loc) · 1.23 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
40
41
42
43
44
45
46
47
const express = require('express')
const path = require('path')
const busboy = require('connect-busboy')
const spawn = require('child_process').spawn
const app = express()
const router = express.Router()
app.use(busboy())
app.use('/', router)
/**
* Endpoint for uploading a csv file
*/
router.post('/csv',(req,res) => {
// Pass the req to busboy middleware
req.pipe(req.busboy)
req.busboy.on('file', function (fieldname, file, filename) {
// Invoke the python command
var subprocess = spawn('python3', [path.join(__dirname, "/hestia-utils.py")])
// Gradually build the response string
var result_string = ""
subprocess.stdout.on('data', function(chunk) {
result_string += chunk
})
// Write the received file directly to the standard input of the subprocess
file.pipe(subprocess.stdin)
subprocess.on('close', function(exit_code) {
res.setHeader('content-type', 'text/plain')
res.send(result_string)
})
})
})
/**
* Index route, return a simple index page with a form for upload
*/
router.get('/',(req,res) => {
res.sendFile(path.join(__dirname, "/index.html"))
})
app.listen(8080)
module.exports = app