roster-server 1.2.2 → 1.2.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/demo/www/example.com/index.js +4 -0
- package/demo/www/sio.example.com/client.js +49 -0
- package/demo/www/sio.example.com/index.js +26 -0
- package/demo/www/subdomain.example.com/index.js +8 -0
- package/index.js +8 -6
- package/package.json +1 -1
- package/demo/www/eample.com/index.js +0 -28
- package/demo/www/server.com/index.js +0 -8
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const { io } = require("socket.io-client");
|
|
2
|
+
|
|
3
|
+
// Connect to the server
|
|
4
|
+
const socket = io('https://test.zentara.group', {
|
|
5
|
+
rejectUnauthorized: false // Only use this in development
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
// Handle connection
|
|
9
|
+
socket.on('connect', () => {
|
|
10
|
+
console.log('Connected to server');
|
|
11
|
+
|
|
12
|
+
// Start ping-pong
|
|
13
|
+
setInterval(() => {
|
|
14
|
+
const timestamp = Date.now();
|
|
15
|
+
console.log('Sending ping...');
|
|
16
|
+
|
|
17
|
+
// Send message
|
|
18
|
+
socket.emit('chat:message', {
|
|
19
|
+
type: 'ping',
|
|
20
|
+
timestamp: timestamp
|
|
21
|
+
});
|
|
22
|
+
}, 5000); // Send ping every 5 seconds
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// Listen for messages
|
|
26
|
+
socket.on('chat:message', (msg) => {
|
|
27
|
+
if (msg.type === 'ping') {
|
|
28
|
+
// Respond to ping with pong
|
|
29
|
+
socket.emit('chat:message', {
|
|
30
|
+
type: 'pong',
|
|
31
|
+
originalTimestamp: msg.timestamp,
|
|
32
|
+
timestamp: Date.now()
|
|
33
|
+
});
|
|
34
|
+
} else if (msg.type === 'pong') {
|
|
35
|
+
// Calculate latency
|
|
36
|
+
const latency = Date.now() - msg.originalTimestamp;
|
|
37
|
+
console.log(`Received pong! Latency: ${latency}ms`);
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// Handle disconnection
|
|
42
|
+
socket.on('disconnect', () => {
|
|
43
|
+
console.log('Disconnected from server');
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
// Handle errors
|
|
47
|
+
socket.on('error', (error) => {
|
|
48
|
+
console.error('Socket error:', error);
|
|
49
|
+
});
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
const { Server } = require('socket.io');
|
|
3
|
+
|
|
4
|
+
const server = https.createServer();
|
|
5
|
+
|
|
6
|
+
// Initialize Socket.IO with the HTTPS server
|
|
7
|
+
const io = new Server(server);
|
|
8
|
+
|
|
9
|
+
// Handle socket connections
|
|
10
|
+
io.on('connection', (socket) => {
|
|
11
|
+
console.log('A user connected');
|
|
12
|
+
|
|
13
|
+
// Handle chat messages
|
|
14
|
+
socket.on('chat:message', (msg) => {
|
|
15
|
+
console.log('Message received:', msg);
|
|
16
|
+
// Broadcast the message to all connected clients
|
|
17
|
+
io.emit('chat:message', msg);
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// Handle disconnection
|
|
21
|
+
socket.on('disconnect', () => {
|
|
22
|
+
console.log('User disconnected');
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
module.exports = server;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const https = require('https');
|
|
2
|
+
|
|
3
|
+
const server = https.createServer((req, res) => {
|
|
4
|
+
res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
|
|
5
|
+
res.end('"Loco de pensar, queriendo entrar en razón, y el corazón tiene razones que la propia razón nunca entenderá."');
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
module.exports = server;
|
package/index.js
CHANGED
|
@@ -150,18 +150,20 @@ class Roster {
|
|
|
150
150
|
handleRequest(req, res) {
|
|
151
151
|
const host = req.headers.host || '';
|
|
152
152
|
|
|
153
|
+
// Eliminar el puerto del host si está presente
|
|
154
|
+
const cleanHost = host.split(':')[0];
|
|
155
|
+
|
|
153
156
|
// Handle www redirect
|
|
154
|
-
if (
|
|
155
|
-
const newHost =
|
|
157
|
+
if (cleanHost.startsWith('www.')) {
|
|
158
|
+
const newHost = cleanHost.slice(4);
|
|
156
159
|
res.writeHead(301, { Location: `https://${newHost}${req.url}` });
|
|
157
160
|
res.end();
|
|
158
161
|
return;
|
|
159
162
|
}
|
|
160
163
|
|
|
161
164
|
// Find and execute the appropriate site handler
|
|
162
|
-
const siteApp = this.sites[
|
|
165
|
+
const siteApp = this.sites[cleanHost];
|
|
163
166
|
if (siteApp) {
|
|
164
|
-
// Si es un servidor HTTP/HTTPS, usar su event emitter
|
|
165
167
|
if (siteApp.emit) {
|
|
166
168
|
siteApp.emit('request', req, res);
|
|
167
169
|
} else {
|
|
@@ -205,14 +207,14 @@ class Roster {
|
|
|
205
207
|
});
|
|
206
208
|
|
|
207
209
|
httpsServer.listen(443, "0.0.0.0", () => {
|
|
208
|
-
console.info("HTTPS Listening on", httpsServer.address());
|
|
210
|
+
console.info("ℹ️ HTTPS Listening on", httpsServer.address());
|
|
209
211
|
});
|
|
210
212
|
|
|
211
213
|
// Setup HTTP server for ACME challenges
|
|
212
214
|
const httpServer = glx.httpServer();
|
|
213
215
|
|
|
214
216
|
httpServer.listen(80, "0.0.0.0", () => {
|
|
215
|
-
console.info("HTTP Listening on", httpServer.address());
|
|
217
|
+
console.info("ℹ️ HTTP Listening on", httpServer.address());
|
|
216
218
|
});
|
|
217
219
|
});
|
|
218
220
|
}
|
package/package.json
CHANGED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
module.exports = (req, res) => {
|
|
2
|
-
// Send a simple response
|
|
3
|
-
res.writeHead(200, { 'Content-Type': 'text/html' });
|
|
4
|
-
res.end(`
|
|
5
|
-
<!DOCTYPE html>
|
|
6
|
-
<html>
|
|
7
|
-
<head>
|
|
8
|
-
<title>Example Site</title>
|
|
9
|
-
<style>
|
|
10
|
-
body {
|
|
11
|
-
font-family: Arial, sans-serif;
|
|
12
|
-
max-width: 800px;
|
|
13
|
-
margin: 40px auto;
|
|
14
|
-
padding: 0 20px;
|
|
15
|
-
line-height: 1.6;
|
|
16
|
-
}
|
|
17
|
-
h1 { color: #333; }
|
|
18
|
-
</style>
|
|
19
|
-
</head>
|
|
20
|
-
<body>
|
|
21
|
-
<h1>Welcome to Example.com</h1>
|
|
22
|
-
<p>This is a sample page served by the Roster server.</p>
|
|
23
|
-
<p>Request received from: ${req.headers.host}</p>
|
|
24
|
-
<p>URL path: ${req.url}</p>
|
|
25
|
-
</body>
|
|
26
|
-
</html>
|
|
27
|
-
`);
|
|
28
|
-
};
|