-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (35 loc) · 1.03 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
'use strict'
// Load settings
const info = require('./package')
const port = process.env.PORT || 3000
const database = process.env.DATABASE || 'mongodb://localhost:27017/mobyourlife'
// Load modules
const restify = require('restify')
const bunyan = require('bunyan')
const mongoose = require('mongoose')
// Initialise logging
const log = bunyan.createLogger({
name: info.name
})
// Setup Restify parameters
var server = restify.createServer({
name: info.name,
version: info.version,
log: log
})
// Log all requests
server.on('after', restify.auditLogger({ log: log }))
// Connect to the database
mongoose.connect(database)
// Setup routing
const users = require('./controllers/users')
server.get('/users', users.index)
const sites = require('./controllers/sites')
server.get('/sites', sites.index)
server.get('/sites/:id', sites.get)
const contents = require('./controllers/contents')
server.get('/contents', contents.index)
// Start listening Restify
server.listen(port, () => {
log.info(`${server.name} listening at ${server.url}`)
})