-
Notifications
You must be signed in to change notification settings - Fork 8
/
client.js
82 lines (69 loc) · 1.99 KB
/
client.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
"use strict";
var app,
bodyParser = require('body-parser'),
express = require('express'),
morgan = require('morgan'),
nconf = require('nconf'),
packageJson = require('./package.json'),
server,
textParser = bodyParser.text({ type: '*/xml'}),
urlencodedParser = bodyParser.urlencoded({ extended: false });
require('console-stamp')(console, 'HH:MM:ss.l');
// Setup nconf to use (in-order):
// 1. Overrides
// 2. Command-line arguments
// 3. Environment variables
// 4. A config.json file
// 5. Default values
nconf
.overrides({
'APP_NAME': 'rssCloudClient',
'APP_VERSION': packageJson.version,
})
.argv()
.env()
.defaults({
"DOMAIN": "localhost",
"PORT": 9000
});
console.log(nconf.get('APP_NAME') + ' ' + nconf.get('APP_VERSION'));
morgan.format('mydate', function() {
var df = require('dateformat');
return df(new Date(), 'HH:MM:ss.l');
});
app = express();
app.use(morgan('[:mydate] :method :url :status :res[content-length] - :remote-addr - :response-time ms'));
app.use(express.static('public', {
dotfiles: 'ignore',
maxAge: '1d'
}));
app.post('/RPC2', textParser, function (req, res) {
console.log('rpc');
console.dir(req.body);
res.send('');
})
app.get('/*', function (req, res) {
var challenge = req.query.challenge || "";
console.log('get');
console.dir(req.query);
res.send(challenge);
});
app.post('/*', urlencodedParser, function (req, res) {
console.log('post');
console.dir(req.body);
res.send('');
});
server = app.listen(nconf.get('PORT'), function () {
var host = nconf.get('DOMAIN'),
port = server.address().port;
console.log('Listening at http://%s:%s', host, port);
})
.on('error', function (error) {
switch (error.code) {
case 'EADDRINUSE':
console.log('Error: Port ' + nconf.get('PORT') + ' is already in use.');
break;
default:
console.log(error.code);
}
});