-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
56 lines (48 loc) · 1.6 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
50
51
52
53
54
55
56
'use strict'
const http = require('http')
const fs = require('fs');
const express = require('express');
const app = express();
const cors = require('cors');
app.use(cors());
app.use(express.json());
app.options('*', cors());
console.log('Сервер работает')
app.use(express.static(__dirname + "/public"));
app.get("/", function(request, response){
response.send("/index.html");
});
let robo = require('./serverParts/robot')
app.get('/robot*', function (req, res) {
let arrURL = req.url.split('/')
if (arrURL.length === 6) {
res.json(robo[arrURL[2]](arrURL[3], arrURL[4], arrURL[5]));
} else if (arrURL.length === 5) {
res.json(robo[arrURL[2]](arrURL[3], arrURL[4]));
} else if (arrURL.length === 4) {
res.json(robo[arrURL[2]](arrURL[3]));
} else {
// console.log(arrURL, req.url);
res.json(robo[arrURL[2]]());
}
});
let analizer = require('./serverParts/picAnalizer')
app.get('/analize*', function (req, res) {
let arrURL = req.url.split('/')
robo.prtSc(arrURL[2],arrURL[3],arrURL[4],arrURL[5])
.then((res) => analizer(res)
.then((response) => res.json(response)))
});
app.post('/data', function(request, response){
fs.readFile('serverParts/resultsMay.json', function (err, data) {
var json = JSON.parse(data);
let date = new Date()
json[date.toLocaleString()] = request.body
fs.writeFile("serverParts/resultsMay.json", JSON.stringify(json), function(err){
if (err) throw err;
console.log('The "data to append" was appended to file!');
});
})
response.json('Отправлены на сервер данные')
});
app.listen(3000);