-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsolution_app.js
38 lines (30 loc) · 992 Bytes
/
solution_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
var express = require('express');
var request = require('request');
var app = express();
app.set('view engine', 'ejs');
app.get('/', function(req,res) {
res.render('index');
});
app.get('/search', function(req,res) {
console.log("\n\n\n\nI AM REQ.QUERY",req.query);
var urlEndpoint = 'http://www.omdbapi.com?s=';
var query = req.query.q.split(' ').join('+');
request(urlEndpoint + query, function(err, response, body) {
if (!err && response.statusCode === 200) {
var apiMovies = JSON.parse(body).Search;
res.render('search', {movies: apiMovies});
}
});
});
app.get('/movie', function(req,res) {
console.log("\n\n\n\nI AM REQ.QUERY",req.query);
var urlEndpoint = 'http://www.omdbapi.com?i=';
var query = req.query.id;
request(urlEndpoint + query, function(err, response, body) {
if (!err && response.statusCode === 200) {
var apiMovie = JSON.parse(body);
res.render('movie', {movie: apiMovie});
}
});
});
app.listen(3000);