-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.ts
executable file
·62 lines (55 loc) · 1.3 KB
/
index.ts
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
/**
* Bootstrap your app
*/
import Promise from 'bluebird';
import mongoose from 'mongoose';
import config from './server/config';
import Express from './server/config/express';
/**
* Promisify All The Mongoose
* @param mongoose
*/
Promise.promisifyAll(mongoose);
/**
* Connecting Mongoose
* @param uris
* @param options
*/
mongoose.connect(config.db, {
bufferMaxEntries: 0,
keepAlive: true,
reconnectInterval: 500,
reconnectTries: 30,
socketTimeoutMS: 0,
useNewUrlParser: true,
useUnifiedTopology: true
});
/**
* Throw error when not able to connect to database
*/
mongoose.connection.on('error', () => {
throw new Error(`unable to connect to database: ${config.db}`);
});
/**
* Mongodb connected to database
*/
mongoose.connection.once('open', () => {
console.log('🚀 Connected to mongo database');
});
/**
* Initialize Express
*/
const ExpressServer = new Express();
ExpressServer.init();
/**
* Listen to port
*/
ExpressServer.httpServer.listen(process.env.PORT || config.port, () => {
console.log(`🚀 Server ready at ${config.port}`);
console.log(
`🚀 Server ready at http://localhost:${config.port}${ExpressServer.server.graphqlPath}`
);
console.log(
`🚀 Subscriptions ready at ws://localhost:${config.port}${ExpressServer.server.subscriptionsPath}`
);
});