-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpilotServeur.js
More file actions
110 lines (93 loc) · 2.33 KB
/
pilotServeur.js
File metadata and controls
110 lines (93 loc) · 2.33 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
var https = require('https');
var express = require('express');
var path = require('path');
var bodyParser = require('body-parser');
var fs = require("fs");
var Ddos = require('ddos');
var httpsPort = 8089;
var app = express();
var mongoClient = require('mongodb').MongoClient;
var axios = require("axios");
//Prevent ddos attacks
var ddos = new Ddos({burst:10, limit:15});
app.use(ddos.express);
//initi parser
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({
extended: true
}));
//init crypto
var options = {
key: fs.readFileSync('encryption/server.key'),
cert: fs.readFileSync('encryption/server.crt')
};
//authorize access to public directory to server html, css, js
app.use(express.static(path.join(__dirname, 'public')));
//login server
require("./taskServer");
//task server
require("./loginServeur");
app.post('/login', function(req, res) {
axios.post("http://127.0.0.1:8090/login", req.body).then(
function(response) {
res.send(response.data);
},
function(error) {
throw error;
}).catch(function(error) {
console.log(error);
});
});
app.post('/addtask', function(req, res) {
axios.post("http://127.0.0.1:8091/addtask", req.body).then(
function(response) {
res.send(response.data);
},
function(error) {
throw error;
});
});
app.post('/taskdone', function(req, res) {
axios.post("http://127.0.0.1:8091/taskdone", req.body).then(
function(response) {
res.send(response.data);
},
function(error) {
throw error;
});
});
app.post('/deletetask', function(req, res) {
axios.post("http://127.0.0.1:8091/deletetask", req.body).then(
function(response) {
res.send(response.data);
},
function(error) {
throw error;
});
});
app.post('/gettasks', function(req, res) {
axios.post("http://127.0.0.1:8091/gettasks",req.body).then(
function(response) {
res.send(response.data);
},
function(error) {
console.log("Error occured while gettasks redirect.");
throw error;
});
});
app.post('/registrate', function(req, res) {
axios.post("http://127.0.0.1:8090/registrate", req.body).then(
function(response) {
if (response.data.errorSet.length <= 0) {
res.send(response.data);
} else {
res.send(response.data);
}
},
function(error) {
throw error;
});
});
https.createServer(options, app).listen(httpsPort, function() {
console.log('Started pilotServer!');
});