-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
76 lines (74 loc) · 2.09 KB
/
app.js
File metadata and controls
76 lines (74 loc) · 2.09 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
var weather = require('./app/weather');
var location = require('./app/location');
var weatherAll = require('./app/weatherForMonth')
var express = require('express');
var middleware=require('./app/middleware')
var app=express();
var ejs = require('ejs')
var ejsData;
app.set('view engine' , 'ejs')
var PORT = process.env.PORT || 3300;
//
app.use(middleware.requireAuthentication);
//
app.use(middleware.logger);
app.get('/',function(req,res){
var errorMessage ='';
var city ;
if(req.query){
if(req.query.city){
city = req.query.city;
}else{
ejsData={};
ejsData.err='';
ejsData.err =" Wether error : code:1002, message: please add query to main link {?city=cityname} ";
res.render('select');// res.render('errors', {data:ejsData});
return;
}
}else{
// res.render('select');
}
weather(city).then(
function(data){
ejsData={
icon:data.icon,
city:data.name,
temp:data.temp
}
return location()
},function(error){
ejsData.error =" Wether error : code: "+error.code+', message: '+error.message;
res.render('errors', {data:ejsData});
return;
}
).then(
function(data){
var str=data.city+' loc '+data.loc;
ejsData.ipCity = data.city;
ejsData.loc = data.loc;
ejsData.ip = data.ip;
ejsData.hostname = data.hostname;
ejsData.region = data.region;
ejsData.country = data.country;
ejsData.org=data.org;
return weatherAll(city);
},function(data){
ejsData.error=" Location error : "+error;
res.render('errors', {data:ejsData});
}
).then(function(data){
ejsData.allWeather = data.arr;
res.render('index', {data:ejsData});
},function(data){
ejsData.error=" Weather error : "+error;
res.render('errors', {data:ejsData});
});
});
// when you want to use static HTML pages.
app.use(express.static(__dirname + '/src'));
app.use('/index',express.static(__dirname+'/public'));
app.use('/info',express.static(__dirname+'/public/info.html'))
//
app.listen(PORT,function(){
console.log('Server work at localhot:'+PORT);
});