This repository was archived by the owner on Apr 15, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·59 lines (53 loc) · 2.22 KB
/
Copy pathindex.js
File metadata and controls
executable file
·59 lines (53 loc) · 2.22 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
57
58
59
// config should be imported before importing any other file
import newrelic from 'newrelic'; // eslint-disable-line
import polyfill from 'babel-polyfill'; // eslint-disable-line
import mongoose from 'mongoose';
import pmx from 'pmx'; // eslint-disable-line
import Sequelize from 'sequelize';
import http from 'http';
import socket from 'socket.io';
import redis from 'socket.io-redis';
import { socketConnection, socketEmitter } from './server/v1/sockets/connection';
pmx.init({ http: true }); // eslint-disable-line enable http keymetris
import config from './config/config'; // eslint-disable-line
import app from './config/express'; // eslint-disable-line
const server = http.createServer(app);
const io = socket.listen(server);
io.adapter(redis(config.redisURL));
const debug = require('debug')('express-mongoose-es6-rest-api:index');
const connectedIO = socketConnection(io);
export const emmiter = socketEmitter(connectedIO);
mongoose.connect(config.mongoUri, { server: { socketOptions: { keepAlive: 1 } } });
mongoose.Promise = global.Promise; // Tell mongoose to use es6 promises
mongoose.connection.on('error', () => {
throw new Error(`unable to connect to database: ${config.mongoUri}`);
});
// Or you can simply use a connection uri
const sequelize = new Sequelize(config.dbUri);
sequelize
.authenticate()
.then(() => {
console.log('Connection has been established successfully.'); // eslint-disable-line
})
.catch((err) => {
console.error('Unable to connect to the database:', err); // eslint-disable-line
});
// Conection to database where is save the GuateCompras data
const sequelizeWidgets = new Sequelize(config.dbUriG); // eslint-disable-line
sequelize
.authenticate()
.then(() => {
console.log('Connection two has been established successfully. GuateCompras'); // eslint-disable-line
})
.catch((err) => {
console.error('Unable to connect to the database:', err); // eslint-disable-line
});
// module.parent check is required to support mocha watch
// src: https://github.com/mochajs/mocha/issues/1912
if (!module.parent) {
// listen on port config.port
server.listen(config.port, () => {
debug(`server started on port ${config.port} (${config.env})`);
});
}
export default app;