This repository has been archived by the owner on Jan 13, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
45 lines (40 loc) · 1.42 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
// Incluímos las dependencias que vamos a usar
var express = require("express"),
path = require('path'),
config = require('./libs/config'),
log = require('./libs/logs')(module),
http = require('http'),
fs = require('fs'),
app = express();
// Configuramos la app para que pueda realizar métodos REST
app.configure(function () {
app.use(express.logger('dev')); // log all requests
app.set('views', __dirname + '/views');
app.set('view engine', 'jade');
app.locals.pretty = true;
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.cookieParser());
app.use(express.urlencoded());
app.use(express.session({ secret: 'super-duper-secret-secret' }));
app.use(require('stylus').middleware({ src: __dirname + '/public' }));
app.use(express.static(__dirname + '/public'));
});
// Routes
routes = require('./controllers/home')(app, log);
app.use(function(req, res, next){
res.status(404);
log.debug('Not found URL: %s',req.url);
res.send({ error: 'Not found' });
return;
});
app.use(function(err, req, res, next){
res.status(err.status || 500);
log.error('Internal error(%d): %s',res.statusCode,err.message);
res.send({ error: err.message });
return;
});
app.server = http.createServer(app);
app.server.listen(config.get('port'), function() {
console.log("Node server running on https://localhost:" + config.get('port'));
});