-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathindex.js
33 lines (27 loc) · 942 Bytes
/
index.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
const mongoose = require("mongoose");
const app = require("./config/express");
const logger = require("./config/logger");
const config = require("./config/config");
// Drawing with certain options throws an error if this is undefined
if (global.CanvasGradient === undefined) {
global.CanvasGradient = () => {};
}
Promise = require("bluebird"); // eslint-disable-line no-global-assign
// plugin bluebird promise in mongoose
mongoose.Promise = Promise;
// connect to mongo db
const mongoUri = config.mongo.host;
mongoose.connect(mongoUri, { keepAlive: 1 });
mongoose.connection.on("error", () => {
throw new Error(`unable to connect to database: ${mongoUri}`);
});
mongoose.connection.once("open", () => {
logger.info(`Connected to database on host ${mongoUri}`);
});
// Start Server
if (config.env !== "test") {
app.listen(config.port, () => {
logger.info(`[SERVER] Listening on port ${config.port}`);
});
}
module.exports = app;