Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (57 loc) · 1.92 KB
/
Copy pathindex.js
File metadata and controls
83 lines (57 loc) · 1.92 KB
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
80
81
82
83
var express = require('express');
var app = express();
const axios=require('axios')
app.set('view engine', 'ejs');
var bodyParser = require("body-parser");
app.use(bodyParser.urlencoded({ extended: true }));
app.listen(3000, function () {
console.log('server is running..3000');
});
app.get('/',function(req,res){
res.render('index');
})
app.post('/save_details',async function(req,res){
axios.post('http://localhost:8080/api',req.body).then((res) => {
console.log(res)
}, (err) => {
console.log(err);
});
res.render('status')
})
app.get('/view_locations',async function(req,res){
let resp= await axios.get('http://localhost:8080/api');
res.render('view_locations',{locations:resp.data})
})
app.get('/view_news',async function(req,res){
let resp= await axios.get('https://newsapi.org/v2/top-headlines?country=us&apiKey=167dde1203594ca598913c5f8114a8e9');
console.log(resp.data.articles)
res.render('view_news',{locations:resp.data.articles})
})
app.get('/find',function(req,res){
res.render('search')
})
app.get('/update/:id',function(req,res){
res.render('update_loc',{loc: req.originalUrl.replace('/update/','')})
})
app.post('/find_details',async function(req,res){
var stringURL ='http://localhost:8080/api/'.concat(req.body.name);
let resp= await axios.get(stringURL);
console.log(resp.data)
res.render('search_locations',{location:resp.data})
})
app.post('/update_details',function(req,res){
var stringURL ='http://localhost:8080/api/'.concat(req.body.name);
axios.patch(stringURL,req.body).then((res) => {
console.log(res.data)
}, (err) => {
console.log(err);
});
res.render('status')
})
app.get('/delete/:id',async function(req,res){
var place=req.originalUrl.replace('/delete/','');
var stringURL ='http://localhost:8080/api/'.concat(place);
let resp= await axios.delete(stringURL);
console.log(resp.data)
res.render('index',{message:resp.data})
})