-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
46 lines (34 loc) · 1.11 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
var Step = require('step');
var packageData = require('./lib/packageData/packageData.js');
var express = require('express');
var app = express();
var winston = require('winston');
app.get('/', function(req, res) {
var cityName = req.query.city || 'London';
Step(
function(){
winston.info('Connection established!');
packageData(cityName, this);
},
function (err, data) {
if (err) throw err;
winston.info('Receive common weather data: ', data);
res.render('index.jade', {
appName: 'WeatherApp',
data: data
});
res.end();
winston.info('Connection closed successfully!');
}
);
});
app.use(express.static(__dirname + '/public'));
app.use(function(req, res){
winston.info('Client wants nonexistent page.');
res.status(404).send('Lets try in another time...');
});
var server = app.listen(2345, function() {
var host = server.address().address;
var port = server.address().port;
winston.info('Start my app at http://%s:%s', host, port);
});