| const express = require('express'); | |
| const http = require('http'); | |
| const app = express(); | |
| const port = 3000; | |
| app.set('view engine', 'ejs'); | |
| app.use(express.static('views')); | |
| app.get('/', (req, res) => { | |
| res.render('index', {'search_input': '', 'images': {'images': []}}); | |
| }); | |
| app.get('/query', (req, res) => { | |
| let search_input = req.query.search_input; | |
| http | |
| .get(`http://pclis:5000/images?search_input=` + search_input, resp => { | |
| let data = ""; | |
| // A chunk of data has been received. | |
| resp.on("data", chunk => { | |
| data += chunk; | |
| }); | |
| // The whole response has been received. Print out the result. | |
| resp.on("end", () => { | |
| images_json = JSON.parse(data); | |
| res.render('index', {'search_input': search_input, | |
| 'images': images_json}); | |
| }); | |
| }) | |
| .on("error", err => { | |
| console.log("Error: " + err.message); | |
| }); | |
| }); | |
| app.listen(port, () => { | |
| console.log(`Server running at http://localhost:${port}`); | |
| }); | |