-
Notifications
You must be signed in to change notification settings - Fork 4
/
app.js
55 lines (41 loc) · 1.52 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
/*
Breve introducción a node como servidor web
-------------------------------------------------------------
Hola Mundo en Express
*/
var express = require('express');
var bodyParser = require('body-parser');
var config = require('./config.json');
var app = express();
var server = require('http').createServer(app);
var io = require('socket.io')(server);
var bll = require('./bll/messages');
var ioEvents = require('./bll/socket-events');
// routers
// ==============================================
var api = require('./routers/api');
var web = require('./routers/web');
// configuramos la aplicacion
// ==============================================
app.use(bodyParser.urlencoded({ extended: true })); //nos permite obtener urlencode data desde body
app.use(bodyParser.json()); //nos permite obtener json data desde body
app.use("/public", express.static(__dirname + '/public'));
app.set('view engine', 'jade');
app.ioStatus = { numUsers: 0, addedUser: false };
// rutas
// ==============================================
app.use('/api', api);
app.use('/', web);
// socket.io
// ==============================================
io.on('connection', function(socket) {
ioEvents(socket, app.ioStatus);
});
// servidor
// ==============================================
var port = process.env.PORT || config.port;
server.listen(port, function() {
bll.setupEnvironment(function() {
console.log('Servidor preparado en http://localhost:%s', server.address().port);
});
});