Initial commit with boiler plate

parent f8806b83
{
"name": "ravenland-api",
"ip": "0.0.0.0",
"port": 9090,
"service_account": {
"user": "secure-user",
"password": "secure-password"
},
"log_location": "logs/",
"throttle": {
"burst": 200,
"rate": 100,
"ip": true
}
}
{
"dependencies": {
"bunyan": "^1.8.12",
"restify": "^7.5.0"
}
}
/*jslint node: true, stupid: true */
'use strict';
var fs = require('fs');
module.exports = function (server) {
fs.readdirSync('./routing').forEach(function (file) {
if (file.substr(-3, 3) === '.js' && file !== 'index.js') {
require('./' + file.replace('.js', ''))(server);
}
});
};
/*jslint node: true, indent: 2 */
/**
* @author Michael Leer
* @requires './config.json'
*/
'use strict';
var restify, bunyan, Elasticsearch, esStream, routing, log, server, config;
restify = require('restify');
routing = require('./routing/');
bunyan = require('bunyan');
config = require('./config.json');
/**
* use Bunyan to log information
*/
log = bunyan.createLogger({
name: config.name,
streams: [
{
path: config.log_location + 'info.json',
level: 'info'
}, {
path: config.log_location + 'error.json',
level: 'error'
}, {
path: config.log_location + 'fatal.json',
level: 'fatal'
}, {
path: config.log_location + 'test.json',
level: 'warn'
}],
serializers: bunyan.stdSerializers
});
/**
* Create restify server
* pulls service name from config
* forces headers such as caching and content type
*/
server = restify.createServer({
name: config.name,
log: log,
formatters: {
'application/json': function(req, res, body) {
//res.setHeader('Cache-Control', 'must-revalidate');
// ONLY send JSON
res.setHeader('Content-Type', 'application/json; charset=utf-8');
return JSON.stringify(body);
}
}
});
/*
// Enforce Rate Limiting
server.use(restify.throttle({
burst: 200,
rate: 100,
ip: true,
overrides: {
'10.0.0.1': {
rate: 0, // unlimited
burst: 0
}
}
}));
*/
server.pre(restify.pre.sanitizePath());
/*jslint unparam:true*/
var auditor = bunyan.createLogger({
name: config.name + '- Auditor',
stream: process.stdout,
serializers: bunyan.stdSerializers
});
routing(server);
server.listen(config.port, function() {
log.debug('%s listening at %s', server.name, server.url);
});
console.log('Server started, on port %s', server.url);
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment