Last active
December 31, 2015 09:19
-
-
Save mikeasick/7966432 to your computer and use it in GitHub Desktop.
Restify serivce produce huge log when trying to hit local Swagger UI at http://localhost:4001/docs/index.htm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var restify = require('restify'); | |
var bunyan = require('bunyan'); | |
var restifySwagger = require('node-restify-swagger'); | |
var restifyValidation = require('node-restify-validation'); | |
var pathSep = "/"; | |
var processName = 'vitals_rt'; | |
var log = createLogger(processName); | |
var valid_increment_units = ['year', 'quarter', 'month', 'week', 'day', 'hour', 'minute', | |
'm','s','h','w','M' | |
]; | |
var server = module.exports.server = restify.createServer({ | |
name: processName, | |
version: '0.0.1', // todo does not work! | |
log: log | |
}); | |
configureServer(server); | |
server.pre(standardPre()); | |
restifySwagger.configure(server); | |
server.get( | |
{ | |
url: pathSep + "vitals", | |
swagger: { | |
summary: 'get a time series of vitals for the given user', | |
notes: 'Status=Unstable', | |
nickname: 'getVitals' | |
}, | |
validation: { | |
u_gid: { isRequired: true, scope: 'query', description: 'user guid' }, | |
start_datetime: { isRequired: true, scope: 'query', isDate: true, description: 'start date of the query' }, | |
end_datetime: { isRequired: true, scope: 'query', isDate: true, description: 'end date of the query' }, | |
increment: { isRequired: true, scope: 'query', isInt: true, min: 1, max: 100, description: 'time increment for summaries' }, | |
increment_unit: { isRequired: true, scope: 'query', isIn: valid_increment_units, description: 'increment' } | |
} | |
}, | |
function (req, res, next) { | |
res.send(req.params); | |
return next(); | |
} | |
); | |
/** | |
* Serve static swagger resources | |
**/ | |
server.get(/^\/docs\/?.*/, restify.serveStatic({directory: './swagger-ui/docs'})); | |
/************ end routes *******************/ | |
restifySwagger.loadRestifyRoutes(); | |
server.listen(4001, function () { | |
log.info('%s listening at %s', server.name, server.url); | |
}); | |
function createLogger(logName) { | |
console.log("creating logger with %s", logName); | |
return bunyan.createLogger({ | |
name: logName, | |
level: process.env.LOG_LEVEL || 'debug', | |
streams: [ | |
{ | |
stream: process.stderr, | |
level: 'info' | |
}, | |
{ | |
path: logName + '.log', | |
level: 'info' | |
} | |
], | |
serializers: bunyan.std | |
}); | |
} | |
function standardPre() { | |
return function (request, response, next) { | |
request.log.info({req: request}, 'start'); | |
return next(); | |
} | |
} | |
function configureServer(server) { | |
server | |
.use(restify.acceptParser(server.acceptable)) | |
.use(function (req, res, next) { | |
req.connection.setTimeout(600 * 1000); | |
res.connection.setTimeout(600 * 1000); //**Edited** | |
next(); | |
}) | |
.use(restify.authorizationParser()) | |
.use(restify.fullResponse()) | |
.use(restify.queryParser()) | |
.use(restify.dateParser(800)) | |
.use(restify.gzipResponse()) | |
.use(restifyValidation.validationPlugin({ errorsAsArray: false })) | |
.use(restify.bodyParser()) | |
.use(restify.throttle({ | |
burst: 100, | |
rate: 50, | |
ip: true, // throttle based on source ip address | |
overrides: { | |
'127.0.0.1': { | |
rate: 0, // unlimited | |
burst: 0 | |
} | |
} | |
})); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment