-
Notifications
You must be signed in to change notification settings - Fork 0
/
worker.js
49 lines (31 loc) · 1006 Bytes
/
worker.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
46
47
48
49
/*global module:true, require:true, console:true, process:true */
'use strict';
var path = require('path')
, restify = require('restify');
exports.createServer = createServer;
/*
* Set up server
* @return the created server
*/
function createServer (logger) {
var config = {
name: require(path.join(__dirname, 'package')).name
};
if (logger) config.log = logger;
var server = restify.createServer(config);
server.use(restify.acceptParser(server.acceptable));
server.use(restify.queryParser());
server.on('NotFound', function (req, res, next) {
if (logger) logger.debug('404', 'Request for ' + req.url + ' not found. No route.');
res.send(404, req.url + ' was not found');
});
if (logger) server.on('after', restify.auditLogger({ log: logger }));
// DEFINE ROUTES
// sample route
// USAGE EXAMPLE: /test
server.get('/test', function (req, res, next) {
res.send({'result': 'test'});
return next();
});
return server;
}