-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
35 lines (33 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
const config = require('./config');
const restify = require('restify');
const restifyPlugins = require('restify').plugins;
const restifyValidation = require('node-restify-validation');
const restifyErrors = require('restify-errors');
/**
* Initialize Server
*/
const server = restify.createServer({
name: config.name,
version: config.version,
});
/**
* Middleware
*/
server.use(restifyPlugins.jsonBodyParser({ mapParams: false }));
server.use(restifyPlugins.acceptParser(server.acceptable));
server.use(restifyPlugins.queryParser({ mapParams: true }));
server.use(restifyPlugins.fullResponse());
server.use(restifyValidation.validationPlugin( {
// Shows errors as an array
errorsAsArray: false,
// Not exclude incoming variables not specified in validator rules
forbidUndefinedVariables: false,
errorHandler: restifyErrors.InvalidArgumentError
}));
/**
* Start Server
*/
server.listen(config.port, function() {
require('./routes')(server);
console.log('Express server listening on port ' + config.port);
});