-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (51 loc) · 1.84 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
// configuramos app
var express = require("express");
var path = require("path");
var app = express();
app.configure(function () {
console.log('Configuring app');
app.use(express.bodyParser());
app.use(express.methodOverride());
app.use(express.static(path.join(__dirname, 'public')));
app.use(function (req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Methods", 'GET,PUT,POST,DELETE');
res.header('Access-Control-Allow-Headers', 'Content-Type');
if ('OPTIONS' == req.method) {
res.send(200);
} else {
next();
}
});
app.use(app.router);
});
// importamos las rutas;
var analyzeRoutes = require('./routes/analyze-routes.js')(app);
var indexRoutes = require('./routes/index-routes.js')(app);
var movieRoutes = require('./routes/movie-routes.js')(app);
app.get('/', function(req, res) {
res.sendFile('./public/index.html');
});
// cargamos la configuracion
var config = require('./util/config.js');
var logEnv = '-----------------------------------------------\n'+
'NODE_ENV = '+process.env.NODE_ENV +'\n'+
'environment = '+config.properties.environment+'\n'+
'-----------------------------------------------';
console.log(logEnv);
// arrancamos el servidor
var http = require("http");
var server = http.createServer(app);
var port = process.env.PORT || config.properties.port;
server.listen(port, function () {
console.log('node server running on port', port);
});
// conectamos con la base de datos
var mongoose = require('mongoose');
mongoose.connect(config.properties.urlMongoDB, function (error, res) {
if (error) {
console.log('ERROR: connecting to MongoDB Database. ' + error);
} else {
console.log('Connected to MongoDB Database');
}
});