-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
32 lines (26 loc) · 875 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
var restify = require('restify');
process.on('message', function(params) {
function respond(req, res, next) {
console.log('Function triggered');
process.send({ do: 'jodot-alive' });
res.send('triggered ' + req.params.name);
next();
}
function basicAuth (req, res, next) {
res.header('WWW-Authenticate','Basic realm="Duty Trigger"');
if (typeof req.authorization.basic !== 'undefined' &&
(req.authorization.basic.username === params[0]) &&
(req.authorization.basic.password === params[1])) {
return next();
} else {
res.send(401);
return next(false);
}
};
var server = restify.createServer();
server.use(restify.authorizationParser());
server.get('/:name', basicAuth, respond);
server.listen(8080, function() {
console.log('%s listening at %s', server.name, server.url);
});
});