-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (48 loc) · 1.6 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
48
49
50
51
52
53
54
const express = require('express')
const app = express()
const { PythonShell } = require('python-shell')
const cors = require('cors')
const PORT = process.env.PORT || 5000
app.use(express.json())
app.use(cors({
origin: "*"
}))
app.post('/api/recommendations', async (req, res, next) => {
let options = {
mode: 'text',
pythonOptions: ['-u'],
args: [req.body.movieName]
}
PythonShell.run('./app.py', options, function (err, results) {
if (err) { console.log(err); return; }
// console.log(results.toString())
let recommended_movie_names = []
let recommended_movie_posters = []
let recommended_movie_ids = []
// let current_movie_id = 0
let result = []
recommended_movie_names = eval(eval(results)[0])
recommended_movie_posters = eval(eval(results)[1])
recommended_movie_ids = eval(eval(results)[2])
// current_movie_id = eval(eval(results)[3])
for (let i = 0; i < 5; i++) {
result.push({
title: recommended_movie_names[i],
poster: recommended_movie_posters[i],
id: recommended_movie_ids[i]
})
}
res.json(result)
// res.json({ result: result, currentMovieId: current_movie_id })
})
})
if (process.env.NODE_ENV === 'production') {
const path = require('path')
app.use(express.static('client/build'));
app.use('*', (req, res) => {
res.send(path.join(__dirname, "client", "build", "index.html"));
});
}
app.listen(PORT, () => {
console.log('Server listening on port ' + PORT)
})