-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
67 lines (57 loc) · 1.81 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
var express = require('express'),
http = require('http'),
models = require('./model'),
db,
Comune,
mongoose = require('mongoose');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io').listen(server);
if ('development' == app.get('env')) {
app.set('db-uri', 'mongodb://localhost/nodefordummies');
app.use(express.errorHandler({ dumpExceptions: true }));
app.set('view options', {
pretty: true
});
}
// production only
if ('production' == app.get('env')) {
app.set('db-uri', 'mongodb://heroku:[email protected]:10017/app7875330');
}
var db = mongoose.connect(app.set('db-uri'));
var concentratore = require('./Concentratore').concentratore(io, mongoose);
app.set('title', 'MiaApplication');
app.set('views', __dirname + '/views');
app.use('public', express.static(__dirname + '/public'));
app.use(express.bodyParser());
app.get('/eccezione', function (req, res) {
res.render('index.jade' );
});
var port = process.env.PORT || 3000;
app.get('/eccezione/getAll', function (req, res) {
console.log("Inizio ricerca...");
mongoose.model('eccezioneModel').find({},
function (err, eccezioni) {
eccezioni = eccezioni.map(function (d) {
return {
messaggio: d.messaggio,
id: d._id,
mittente: d.mittente
};
});
console.log("Fine ricerca");
//res.send(eccezioni);
res.render('eccezione.jade',{
"eccezioni":eccezioni,
"port":port
} );
});
console.log("Fine call");
});
app.post('/eccezione', function(req, res){
concentratore.getEccezione(req.body.messaggio, req.body.mittente);
res.send("OK");
});
server.listen(port, function () {
console.log("Listening on " + port);
});