-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
executable file
·68 lines (56 loc) · 1.93 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
require('newrelic');
const express = require('express');
const cors = require('cors');
const bodyParser = require('body-parser');
const configDb = require('./config/db');
const config = require('./config');
const mongoose = require('mongoose');
const session = require('express-session');
const MongoStore = require('connect-mongo')(session);
const graphqlServer = require('express-graphql');
const hotel = require('./routes/hotel');
const coronavirus = require('./routes/coronavirus');
const schema = require('./controllers/v2/schema');
const { getLogger, logHandler, terminate } = require('@jwt/utils')
const app = express();
const http = require('http');
const socketIO = require('socket.io');
const server = http.createServer(app);
module.exports.io = socketIO(server);
const socketEvento = require('./config-socket/socketEvento');
const log = getLogger(__dirname, __filename)
app.use(cors(({exposedHeaders: ['Content-Length', 'X-Total-Count']})));
// Manejo de sesiones
app.use(session({
secret: 'some-secret',
resave: false,
saveUninitialized: false,
store: new MongoStore({
mongooseConnection: configDb,
})
}));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.use(logHandler);
// API REST v1
app.use('/api/v1', hotel);
app.use('/api/v1', coronavirus);
// API v2 con GraphQL
app.use('/api/v2/graphql', graphqlServer({
schema: schema,
graphiql: true
}));
app.disable('etag');
app.disable('x-powered-by');
app.get('/', (req, res) => {
res.send('Hola api rest de Hoteles! creado por Fernando López');
});
if (!module.parent) {
server.listen(config.port, () => {
log.info(`Server funcionando en puerto ${config.port}`);
})
process.on('SIGINT', terminate(0, 'SIGINT'))
process.on('SIGTERM', terminate(0, 'SIGTERM'))
process.on('uncaughtException', terminate(1, 'uncaughtException'))
process.on('unhandledRejection', terminate(1, 'unhandledRejection'))
}