-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
80 lines (66 loc) · 2.49 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
68
69
70
71
72
73
74
75
76
77
78
79
80
'use strict'
/* var app = require('./app');
var port = process.env.PORT || 3000; */
// requires
var express = require('express');
const mongoose = require("mongoose");
var bodyParser = require('body-parser');
// Inicializar variables
var app = express();
// CORS
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*"); // update to match the domain you will make the request from
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
res.header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS");
next();
});
// Body Parser
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
app.use(bodyParser.json());
// mongo cloud
const port = process.env.PORT || 3000;
const MC_url = "mongodb+srv://pablo:[email protected]/hospitalDB";
/*
Server index config
permite habilitar acceso a la carpeta de imagenes subidas en el servidor
<direccion server>/uploads
Ver si vale la pena habilitar esto. Si se necesita ver otra carpeta cambiar esto en
la tercera linea.
Temporalmente desabilitado
*/
// var serveIndex = require('serve-index');
// app.use(express.static(__dirname + '/'))
// app.use('/uploads', serveIndex(__dirname + '/uploads'));
// Importar rutas
var appRoutes = require('./routes/app');
var usuarioRoutes = require('./routes/usuario');
var loginRoutes = require('./routes/login');
var hospitalRoutes = require('./routes/hospital');
var medicoRoutes = require('./routes/medico');
var busquedaRoutes = require('./routes/busqueda');
var uploadRoutes = require('./routes/upload');
var imagenesRoutes = require('./routes/imagenes');
app.use('/usuario', usuarioRoutes);
app.use('/login', loginRoutes);
app.use('/hospital', hospitalRoutes);
app.use('/medico', medicoRoutes);
app.use('/busqueda', busquedaRoutes);
app.use('/upload', uploadRoutes);
app.use('/img', imagenesRoutes);
app.use('/', appRoutes);
mongoose.Promise = global.Promise;
mongoose.connect(MC_url, {
'useNewUrlParser': true,
'useFindAndModify': false,
'useUnifiedTopology': true
})
.then(() => {
console.log('\n'.repeat(50));
console.log('Conexiôn a Cloud MongoDb: \x1b[32m%s\x1b[0m', 'online');
// Escuchar peticiones
app.listen(port, () => {
console.log('Express server en puerto 3000: \x1b[32m%s\x1b[0m', 'online');
});
})
.catch((error) => console.log('Error al abrir la base de datos', error));