roster-server 1.2.2 → 1.2.6

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.
@@ -0,0 +1,4 @@
1
+ module.exports = (req, res) => {
2
+ res.writeHead(200, { 'Content-Type': 'text/plain; charset=utf-8' });
3
+ res.end('"Loco de pensar, queriendo entrar en razón, y el corazón tiene razones que la propia razón nunca entenderá."');
4
+ };
@@ -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,33 @@
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
+ cors: {
9
+ origin: "*",
10
+ methods: ["GET", "POST"]
11
+ },
12
+ allowEIO3: true,
13
+ transports: ['websocket', 'polling']
14
+ });
15
+
16
+ // Handle socket connections
17
+ io.on('connection', (socket) => {
18
+ console.log('A user connected');
19
+
20
+ // Handle chat messages
21
+ socket.on('chat:message', (msg) => {
22
+ console.log('Message received:', msg);
23
+ // Broadcast the message to all connected clients
24
+ io.emit('chat:message', msg);
25
+ });
26
+
27
+ // Handle disconnection
28
+ socket.on('disconnect', () => {
29
+ console.log('User disconnected');
30
+ });
31
+ });
32
+
33
+ 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 (host.startsWith('www.')) {
155
- const newHost = host.slice(4);
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[host];
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 {
@@ -182,11 +184,9 @@ class Roster {
182
184
  staging: this.staging,
183
185
  manager: { module: "@greenlock/manager" },
184
186
  approveDomains: (opts, certs, cb) => {
185
- // If certs is defined, we already have a certificate and are renewing it
186
187
  if (certs) {
187
188
  opts.domains = certs.altnames;
188
189
  } else {
189
- // If it's a new request, verify if the domain is in our list
190
190
  if (this.domains.includes(opts.domain)) {
191
191
  opts.email = this.maintainerEmail;
192
192
  opts.agreeTos = true;
@@ -204,15 +204,25 @@ class Roster {
204
204
  this.handleRequest(req, res);
205
205
  });
206
206
 
207
+ // Agregar soporte para WebSocket
208
+ httpsServer.on('upgrade', (req, socket, head) => {
209
+ const host = req.headers.host?.split(':')[0] || '';
210
+ const siteApp = this.sites[host];
211
+
212
+ if (siteApp && siteApp.upgrade) {
213
+ siteApp.upgrade(req, socket, head);
214
+ }
215
+ });
216
+
207
217
  httpsServer.listen(443, "0.0.0.0", () => {
208
- console.info("HTTPS Listening on", httpsServer.address());
218
+ console.info("ℹ️ HTTPS Listening on", httpsServer.address());
209
219
  });
210
220
 
211
221
  // Setup HTTP server for ACME challenges
212
222
  const httpServer = glx.httpServer();
213
223
 
214
224
  httpServer.listen(80, "0.0.0.0", () => {
215
- console.info("HTTP Listening on", httpServer.address());
225
+ console.info("ℹ️ HTTP Listening on", httpServer.address());
216
226
  });
217
227
  });
218
228
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roster-server",
3
- "version": "1.2.2",
3
+ "version": "1.2.6",
4
4
  "description": "👾 RosterServer - A domain host router to host multiple HTTPS.",
5
5
  "main": "index.js",
6
6
  "scripts": {
@@ -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
- };
@@ -1,8 +0,0 @@
1
- const https = require('https');
2
-
3
- const server = https.createServer((req, res) => {
4
- res.writeHead(200);
5
- res.end('¡Hola desde mi sitio!');
6
- });
7
-
8
- module.exports = server;