roster-server 1.2.0 → 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.
@@ -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,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
@@ -28,7 +28,10 @@ class Roster {
28
28
  for (const indexFile of possibleIndexFiles) {
29
29
  const indexPath = path.join(domainPath, indexFile);
30
30
  if (fs.existsSync(indexPath)) {
31
- siteApp = require(indexPath);
31
+ const module = require(indexPath);
32
+ // Si el módulo es una función o un servidor, usarlo directamente
33
+ siteApp = typeof module === 'function' ? module :
34
+ (module.handleRequest || module.handle || module);
32
35
  loadedFile = indexFile;
33
36
  break;
34
37
  }
@@ -147,18 +150,25 @@ class Roster {
147
150
  handleRequest(req, res) {
148
151
  const host = req.headers.host || '';
149
152
 
153
+ // Eliminar el puerto del host si está presente
154
+ const cleanHost = host.split(':')[0];
155
+
150
156
  // Handle www redirect
151
- if (host.startsWith('www.')) {
152
- const newHost = host.slice(4);
157
+ if (cleanHost.startsWith('www.')) {
158
+ const newHost = cleanHost.slice(4);
153
159
  res.writeHead(301, { Location: `https://${newHost}${req.url}` });
154
160
  res.end();
155
161
  return;
156
162
  }
157
163
 
158
164
  // Find and execute the appropriate site handler
159
- const siteApp = this.sites[host];
165
+ const siteApp = this.sites[cleanHost];
160
166
  if (siteApp) {
161
- siteApp(req, res);
167
+ if (siteApp.emit) {
168
+ siteApp.emit('request', req, res);
169
+ } else {
170
+ siteApp(req, res);
171
+ }
162
172
  } else {
163
173
  res.writeHead(404);
164
174
  res.end('Site not found');
@@ -197,14 +207,14 @@ class Roster {
197
207
  });
198
208
 
199
209
  httpsServer.listen(443, "0.0.0.0", () => {
200
- console.info("HTTPS Listening on", httpsServer.address());
210
+ console.info("ℹ️ HTTPS Listening on", httpsServer.address());
201
211
  });
202
212
 
203
213
  // Setup HTTP server for ACME challenges
204
214
  const httpServer = glx.httpServer();
205
215
 
206
216
  httpServer.listen(80, "0.0.0.0", () => {
207
- console.info("HTTP Listening on", httpServer.address());
217
+ console.info("ℹ️ HTTP Listening on", httpServer.address());
208
218
  });
209
219
  });
210
220
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "roster-server",
3
- "version": "1.2.0",
3
+ "version": "1.2.4",
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
- };