This repository has been archived by the owner on Aug 5, 2021. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
89 lines (68 loc) · 2.2 KB
/
main.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
83
84
85
86
87
88
89
/*
This file is part of Turquoise.
Copyright (c) Snazzah ???-2019
Copyright (c) Yamboy1 (and contributors) 2019
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
'use strict';
var moment = require("moment");
var fs = require("fs");
var cors = require("cors");
var config = require("./config.json")
var express = require('express');
var app = express();
var http = require('http').Server(app);
var chalk = require("chalk");
var RateLimit = require('express-rate-limit');
var client = require('redis').createClient(config.redis);
var limitr = require('express-limiter')(app, client);
let bodyParser = require('body-parser');
// App Settings \\
app.set("json spaces", 4);
// Ratelimit \\
let buildLimit = function(path, method){
return {
path: path,
method: method,
lookup: 'connection.remoteAddress',
skipHeaders: true,
total: 25,
expire: 1*60*1000,
onRateLimited: function(req, res, next){
res.status(429).json({status: 429, error: "Too many requests, please try again later."});
}
};
};
//limitr(buildLimit('/trello*', 'get'));
var log = function(level, message){
var lg = "["+moment().format()+"] "+message;
switch(Number(level)){
case 1:
console.log(chalk.green(lg));
break;
case 2:
console.log(chalk.yellow(lg));
break;
case 3:
console.log(chalk.red(lg));
break;
}
};
app.use(bodyParser.json());
app.use(cors());
app.use(require('./middleware/error.js'));
app.use('/trello', require('./router/trello.js'));
app.use('/trellobeta', require('./router/trellobeta.js'));
// Non-Ratelimited endpoints \\
http.listen(config.recv_port, function(){
console.log(chalk.green(`listening on *:${config.recv_port}`));
});