-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
89 lines (77 loc) · 1.79 KB
/
Copy pathserver.js
File metadata and controls
89 lines (77 loc) · 1.79 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
84
85
86
87
88
const express=require("express");
const geoCode =require("./utils/geoCode");
const foreCast=require("./utils/foreCast");
const app=express();
app.get("",(req,res)=>{
res.json({
title:"Weather Page",
name:"Weather"
})
})
app.get("/about",(req,res)=>{
res.json({
name:"About",
title:"About Page"
})
})
app.get("/help",(req,res)=>{
res.json({
title:"Help Page",
name:"Help"
})
})
app.get("/weather",(req,res)=>{
if(!req.query.address){
res.json({
error:"You must provide a address"
})
}
else{
geoCode(req.query.address,(err,data)=>{
if(err){
res.json({error:"Cant find that address"})
}
else{
foreCast(data.latitude,data.longitude,data.location,(error,response)=>{
if(error){
res.json({error})
}
else{
res.json({
weather:response.Weather,
Temperature:response.Temperature,
Location:response.Location
})
}
})
}
})
}
})
app.get("/products",(req,res)=>{
if(!req.query.search){
res.json({
error:"You must provide a search term"
})
}
else{
res.json({
products:[]
})
}
})
app.get("/help/*",(req,res)=>{
res.json("404",{
errmsg:"Help article not found",
title:"404"
})
})
app.get("*",(req,res)=>{
res.json("404",{
errmsg:"Page not found",
title:"404"
})
})
app.listen(5000,()=>{
console.log("Server Listening and up on 5000")
})