-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
53 lines (43 loc) · 1.24 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
'use strict'
/**
* Module Dependencies
*/
const config = require('./config'),
restify = require('restify'),
restifyPlugins = require('restify').plugins,
mongodb = require('mongodb').MongoClient
/**
* Initialize Server
*/
const server = restify.createServer({
name : config.name,
version : config.version
})
/**
* Bundled Plugins (http://restify.com/#bundled-plugins)
*/
server.use(restifyPlugins.jsonBodyParser({ mapParams: true }))
server.use(restifyPlugins.acceptParser(server.acceptable))
server.use(restifyPlugins.queryParser({ mapParams: true }))
server.use(restifyPlugins.fullResponse())
/**
* Lift Server, Connect to DB & Require Route File
*/
server.listen(config.port, () => {
// establish connection to mongodb atlas
mongodb.connect(config.db.uri, (err, db) => {
if (err) {
console.log('An error occurred while attempting to connect to MongoDB', err)
process.exit(1)
}
console.log(
'%s v%s ready to accept connections at url %s on port %s in %s environment.',
server.name,
config.version,
server.url,
config.port,
config.env
)
require('./routes')({ db, server })
})
})