-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
54 lines (46 loc) · 1.17 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
const fs = require("fs");
const express = require('express');
const app = express();
const https = require('https');
const server = https.createServer({
key: fs.readFileSync("./privkey.pem"),
cert: fs.readFileSync("./cert.pem")
},app);
const socketio = require('socket.io');
const io = socketio(server);
const net = require("net");
const pako = require("./pako.js");
const uuid = require("uuid");
app.use(express.static("./static"));
server.listen(443, () => {
console.log("Server started");
});
io.on("connection", client => {
console.log("Connected");
client.on("image", x => {
let i = pako.ungzip(x, {to: 'string'});
let c = new net.Socket();
c.connect(10000, "localhost", function(){
c.write((i.length + "").length + "");
c.write(i.length + "");
c.write(i);
let data = "";
c.on("data", x => {
data+=x;
});
c.on("end", x => {
console.log(data);
client.emit("image", data);
data = undefined;
});
});
});
client.on("save_image", x => {
fs.appendFileSync("images.csv", x);
});
});
const redirector = express();
redirector.get("*", (req, res) => {
res.redirect('https://' + req.headers.host + req.url);
});
redirector.listen(80);