-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathserver.js
35 lines (28 loc) · 964 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
34
35
const express= require('express')
const child_process= require('child_process')
const cors= require('cors')
var path = require('path');
const { saveImage }= require('./utils/fileUpload.js')
const app= express()
const PORT= process.env.PORT || 5000
app.use(express.json({limit: '50mb'}))
app.use(cors());
app.post('/cartoon', (req, res) => {
let imageFileName= saveImage(req.body.img)
try{
child_process.execFileSync('python3', ['./cartoon-filter.py', imageFileName])
return res.sendFile(__dirname+'/filter.jpg')
}
catch(err){
console.error('err', err)
}
})
if (process.env.NODE_ENV === 'production' || process.env.NODE_ENV === 'staging') {
app.use(express.static(path.join(__dirname, 'client/build')));
app.get('*', function (req, res) {
res.sendFile(path.join(__dirname, 'client/build', 'index.html'));
});
};
app.listen(PORT, () => {
console.log(`Server is listening at port ${PORT}`)
})