-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
49 lines (42 loc) · 1.23 KB
/
server.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
function validateToken(token) {
var companyToken = 'KteAYmCSHBoFFteuDQeFP3MY';
var privateToken = 'grkgRpDElgRhlo9LXD1asYdE';
var validTokens = [companyToken, privateToken];
return _.includes(validTokens, token);
}
function validateMethod(method) {
return method === 'GET';
}
function validatePathName(pathname) {
return pathname === '/';
}
function runOneOnOne(input) {
console.log("Input text: %s", input);
}
function handleRequest(req, res) {
console.log('Incoming request url: %s', req.url);
var requestedUrl = url.parse(req.url, extractQueryStringParams);
ASQ()
.all(
done => done(validateMethod(req.method)),
done => done(validatePathName(requestedUrl.pathname)),
done => done(validateToken(requestedUrl.query.token))
)
.then((done, method, path, token) => {
if (method && path && token) done(requestedUrl.query.text)
else done.fail("Invalid request")
})
.then((done, input) => {
done(runOneOnOne(input));
})
.val(val => res.end(':thumbsup: This is working, *bloody hell*...'))
.or(err => {
console.error(err);
res.writeHead(403);
res.end('Boom! Not today...');
});
}
const extractQueryStringParams = true;
var ASQ = require('asynquence');
var _ = require('lodash');
var url = require('url');