-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
54 lines (43 loc) · 1.73 KB
/
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @author Martin Micunda {@link http://martinmicunda.com}
* @copyright Copyright (c) 2015, Martin Micunda
* @license GPL-3.0
*/
'use strict';
// loads environment variables from .env into ENV (process.env)
import dotenv from 'dotenv';
dotenv.config({silent: process.env.NODE_ENV !== 'development'});
import pkg from './package.json';
import koa from './lib/config/koa';
import config from './lib/config/config.js';
import couchbase from './lib/config/couchbase';
const logger = require('mm-node-logger')(module);
const banner = `
*********************************************************************************************
*
* ${pkg.description}
* @version ${pkg.version}
* @author ${pkg.author.name}
* @copyright 2014-${new Date().getFullYear()} ${pkg.author.name}
* @license ${pkg.license}
*
*********************************************************************************************`;
function startServer() {
console.log(banner);
const db = couchbase.connect();
db.on('error', (error) => {
logger.error(`Failed to make a connection to the Couchbase Server ${config.couchbase.endPoint.blue} with bucket '${config.couchbase.bucket.blue}':`, error);
process.exit(1);
});
db.on('connect', () => {
logger.info(`Couchbase connected to ${config.couchbase.endPoint.blue} with bucket ${config.couchbase.bucket.blue}`);
// initialize koa
const app = koa.init();
// start up the server on the port specified in the config after we connected to couchbase
app.listen(config.server.port, () => {
logger.info(`App started on port ${config.server.port} with environment ${config.environment.blue}`);
});
return app;
});
}
export default startServer();