-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
56 lines (48 loc) · 1.52 KB
/
Copy pathapp.js
File metadata and controls
56 lines (48 loc) · 1.52 KB
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
var express = require('express');
var mongoose = require('mongoose');
var body_parser = require('body-parser');
var path = require('path');
var app = express();
const PORT = 6969;
// MIDDLEWARE DE BODY-PARSER
app.use(body_parser.urlencoded({ extended: false }));
app.use(body_parser.json());
// CARGAR RUTAS
var app_routes = require('./routes/app');
var app_usuario = require('./routes/usuario');
var app_login = require('./routes/login');
mongoose.set('useCreateIndex', true);
mongoose.connection.openUri
(
'mongodb://localhost:27017/db_inmobiliaria', { useNewUrlParser: true }, (err, res) =>
{
if (err)
throw err;
else
console.log('Mongo connected in port \x1b[33m 27017\x1b[0m: \x1b[32m%s\x1b[0m', 'Online');
}
);
// CONFIGURAR CABECERAS Y CORS
app.use
(
(req, res, next) =>
{
res.header('Access-Control-Allow-Origin', '*');
res.header('Access-Control-Allow-Headers', 'Authorization, X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Allow-Request-Method');
res.header('Access-Control-Allow-Methods', 'GET, POST, OPTIONS, PUT, DELETE');
res.header('Allow', 'GET, POST, OPTIONS, PUT, DELETE');
next();
}
);
// RUTAS BASE
app.use(express.static(path.join(__dirname, 'public')));
app.use('/usuario', app_usuario);
app.use('/login', app_login);
app.use('/', app_routes);
app.listen
(
PORT, () =>
{
console.log('Server running in port \x1b[33m ' + PORT + '\x1b[0m: \x1b[32m%s\x1b[0m', 'Online');
}
);