roster-server 1.2.0 → 1.2.2
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/server.com/index.js +8 -0
- package/index.js +10 -2
- package/package.json +1 -1
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
|
-
|
|
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
|
}
|
|
@@ -158,7 +161,12 @@ class Roster {
|
|
|
158
161
|
// Find and execute the appropriate site handler
|
|
159
162
|
const siteApp = this.sites[host];
|
|
160
163
|
if (siteApp) {
|
|
161
|
-
|
|
164
|
+
// Si es un servidor HTTP/HTTPS, usar su event emitter
|
|
165
|
+
if (siteApp.emit) {
|
|
166
|
+
siteApp.emit('request', req, res);
|
|
167
|
+
} else {
|
|
168
|
+
siteApp(req, res);
|
|
169
|
+
}
|
|
162
170
|
} else {
|
|
163
171
|
res.writeHead(404);
|
|
164
172
|
res.end('Site not found');
|