-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
44 lines (37 loc) · 1.07 KB
/
app.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
"use strict";
const express = require("express");
const app = express();
const multer = require("multer");
var storage = multer.diskStorage({
destination: __dirname + "/inputs/",
filename: function(req, file, cb) {
cb(null, Date.now() + "-" + file.originalname);
}
});
var upload = multer({ storage: storage });
const { execFile } = require("child_process");
app.use((req, res, next) => {
// allow CORS
res.header("Access-Control-Allow-Origin", "*");
res.header(
"Access-Control-Allow-Headers",
"Origin, X-Requested-With, Content-Type, Accept"
);
next();
});
app.post("/upload", upload.single("file"), (req, res) => {
if (req.body) {
// res.json(req.file)
} else throw "error";
execFile("python", ["predict.py"], (error, stdout, stderr) => {
if (error) {
console.error(`exec error: ${error}`);
return;
}
console.log(stdout);
res.send(stdout);
});
});
const port = process.env.PORT || 4000;
app.listen(port, () => console.log(`Listening on port ${port}.`));
module.exports = app;