-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
79 lines (69 loc) · 2.53 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
var express = require("express");
var app = express();
var request = require("request");
var bodyParser = require("body-parser");
// var NewsAPI = require('newsapi');
// var newsapi = new NewsAPI('API_KEY');
app.use(bodyParser.urlencoded({extended: true}));
app.set("view engine", "ejs");
var article = [
{title:"newsnews",author:"sam",content:"this is the news zzgdf gszfibskjjgzsfb lorem ipsum" ,category:"genral",fc :0}
,{title:"news",author:"sam",content:"this is the news zzgdf gszfibskjjgzsfb lorem ipsum" ,category:"genral",fc :0}
,{title:"newsn",author:"sam",content:"this is the news zzgdf gszfibskjjgzsfb lorem ipsum" ,category:"genral",fc :0}
]
app.get("/", function(req, res){
var data=article;
res.render("results",{data : data});
// var url = 'https://newsapi.org/v2/top-headlines?' +
// 'country=us&' +
// 'apiKey=200561a88ba24bc1b60574b45a63045a';
// request(url, function(error, response, body){
// if(!error && response.statusCode == 200) {
// var data = JSON.parse(body)
// res.render("results", {data: data});
// }
// });
});
// app.get("/campgrounds", function(req, res){
// res.render("campgrounds",{campgrounds:campgrounds});
// });
app.post("/newarticle", function(req, res){
// get data from form and add to campgrounds array
console.log(req.body);
var title = req.body.title;
var author = req.body.author;
var content = req.body.content;
var category = req.body.category;
var newart ={title: title , author : author , content : content , category : category,fc : 0};
article.push(newart);
//redirect back to campgrounds page
res.redirect("/");
});
app.get("/newarticle1", function(req, res){
res.render("new.ejs");
});
// app.get("/results", function(req, res){
// var query = req.query.search;
// var url = "http://omdbapi.com/?s=" + query;
// request(url, function(error, response, body){
// if(!error && response.statusCode == 200) {
// var data = JSON.parse(body)
// res.render("results", {data: data});
// }
// });
// });
app.post("/fakevote/:name", function(req, res){
console.log("b clicked");
console.log(req.params.name);
article.forEach(function(art){
if(req.params.name == art["title"])
{
art["fc"]++;
}
});
res.redirect("/");
});
app.listen(3000, function(){
console.log("Movie App has started!!!");
});
// 200561a88ba24bc1b60574b45a63045a