-
Notifications
You must be signed in to change notification settings - Fork 8
/
index.js
39 lines (29 loc) · 855 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
34
35
36
37
38
const MODULE_ID = 'app:main'
const logger = require('m-logger')
const config = require('./config')
logger.info('%s: initializing', MODULE_ID)
const jwt = require('restify-jwt-community')
const restify = require('restify')
const plugins = require('restify').plugins
const server = restify.createServer()
server.pre(restify.pre.sanitizePath())
server.use(plugins.bodyParser())
logger.verbose('securing with jwt')
// Auth
var jwtConfig = {
secret: config.JWT_SECRET
}
// secure all routes. except /ping
server.use(jwt(jwtConfig).unless({
path: [
config.basePath('/ping'),
config.basePath('/register')
]
}))
// Routes
logger.verbose('loading routes')
require('./routes')(server)
// Serve
server.listen(config.PORT)
logger.info('%s: ready. listening on PORT %d', MODULE_ID, config.PORT)
module.exports = server