-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
111 lines (59 loc) · 2.48 KB
/
index.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const http = require('http');
const express = require('express');
const app = express();
const path = require('path');
const server = require('http').createServer(app);
const files = './public/Files/';
const fs = require('fs');
const bodyParser = require('body-parser');
//---------------------------------------------------- Configuracion del Servidor-----------------------------
const hostname = '127.0.0.1';
const port = 3000;
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencode
//---------------------------------------------------- CONFIGURACION PARA EL SOCKET --------------------------
const io = require('socket.io').listen(server);
io.on('connection',(socket)=>{
console.log("usuario conectado");
//------------------------------------------------- CANAL PARA RECIBIR EL RESULTADO DEL ANALISIS DE PASCAL
socket.on('result',(data)=>{
socket.broadcast.emit('resultadoAnalisis',data); //-------------------- ENVIAMOS UNA SEÑAL AL WEBSOCKET EN JS -----
});
//------------------------------------------------ CANAL PARA RECIBIR EL JSON DEL REPORTE DE LA COMPILACION PREVIAMENTE EN PASCAL
socket.on('reporte',(data)=>{
socket.broadcast.emit('resultadoReporte',data);
});
socket.on("getReporte",(data)=>{
io.emit("reporteStack","");
});
});
app.use(express.static('public'));
app.get("/", function (solictud, respuesta) {
respuesta.sendFile(path.join(__dirname + '/public/Pages/index.html'));
});
app.post("/readFiles", function (solicitud, respuesta) {
let code = solicitud.body.cuerpo;
let allFiles = [];
let codigo = [];
codigo.push({"name": "principal","body":code}); // Es el principal
fs.readdirSync(files).forEach(file => {
allFiles.push(file);
});
allFiles.forEach(element =>{
let dir = path.join(__dirname,'/public/Files/' + element);
let content = fs.readFileSync(dir,).toString('utf8');
element = (element.split("."))[0];
let newFile = {"name": element , "body": content };
codigo.push(newFile);
})
let json = JSON.stringify(codigo);
io.emit('sendCode',json);
respuesta.sendStatus(200);
});
app.get('*', function (solictud, respuesta) {
respuesta.send("Error 404");
});
//------------------------------------------------- Configuracion de IP Y PUERTO -------------------------------------------------
server.listen(port, hostname, () => {
console.log("Cliente Iniciado");
});