vimd 0.3.0 → 0.3.1
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.
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"websocket-server.d.ts","sourceRoot":"","sources":["../../src/core/websocket-server.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"websocket-server.d.ts","sourceRoot":"","sources":["../../src/core/websocket-server.ts"],"names":[],"mappings":"AAUA;;;GAGG;AACH,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAED;;;GAGG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,MAAM,CAAC;IACnB,aAAa,EAAE,MAAM,CAAC;IACtB,WAAW,EAAE,OAAO,CAAC;CACtB;AA0CD;;;GAGG;AACH,qBAAa,eAAe;IAC1B,OAAO,CAAC,UAAU,CAA4B;IAC9C,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,OAAO,CAA6B;IAC5C,OAAO,CAAC,OAAO,CAAyB;IACxC,OAAO,CAAC,KAAK,CAAS;gBAEV,OAAO,EAAE,sBAAsB;IAQ3C;;OAEG;IACH,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,iBAAiB,CAAC;IA4GzC;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IA8B3B;;OAEG;IACH,SAAS,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,OAAO,GAAG,IAAI;IAU7C;;OAEG;IACH,OAAO,CAAC,kBAAkB;CAc3B"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// src/core/websocket-server.ts
|
|
2
2
|
import http from 'http';
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
3
5
|
import polka from 'polka';
|
|
4
6
|
import sirv from 'sirv';
|
|
5
7
|
import { WebSocketServer as WSServer, WebSocket } from 'ws';
|
|
@@ -84,31 +86,38 @@ export class WebSocketServer {
|
|
|
84
86
|
// Create polka app with HTML injection middleware
|
|
85
87
|
const app = polka();
|
|
86
88
|
// Middleware to inject reload script into HTML
|
|
89
|
+
// For HTML files, read directly to avoid sirv streaming issues
|
|
87
90
|
app.use((req, res, next) => {
|
|
88
91
|
// Only process GET requests for HTML files
|
|
89
92
|
if (req.method !== 'GET' || !req.url?.endsWith('.html')) {
|
|
90
93
|
return serve(req, res, next);
|
|
91
94
|
}
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
return
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
95
|
+
// Parse the URL and resolve the file path
|
|
96
|
+
const urlPath = req.url || '/index.html';
|
|
97
|
+
const filePath = path.join(this.options.root, urlPath);
|
|
98
|
+
// Check if file exists
|
|
99
|
+
if (!fs.existsSync(filePath)) {
|
|
100
|
+
// Let sirv handle 404
|
|
101
|
+
return serve(req, res, next);
|
|
102
|
+
}
|
|
103
|
+
try {
|
|
104
|
+
// Read HTML file directly
|
|
105
|
+
const html = fs.readFileSync(filePath, 'utf8');
|
|
106
|
+
// Inject reload script
|
|
107
|
+
const injectedHtml = this.injectReloadScript(html);
|
|
108
|
+
// Send response with proper headers
|
|
109
|
+
res.writeHead(200, {
|
|
110
|
+
'Content-Type': 'text/html; charset=utf-8',
|
|
111
|
+
'Content-Length': Buffer.byteLength(injectedHtml, 'utf8'),
|
|
112
|
+
'Cache-Control': 'no-cache, no-store, must-revalidate',
|
|
113
|
+
});
|
|
114
|
+
res.end(injectedHtml);
|
|
115
|
+
}
|
|
116
|
+
catch (error) {
|
|
117
|
+
// On error, fall back to sirv
|
|
118
|
+
Logger.warn(`Failed to read HTML file: ${filePath}`);
|
|
119
|
+
serve(req, res, next);
|
|
120
|
+
}
|
|
112
121
|
});
|
|
113
122
|
// Create HTTP server
|
|
114
123
|
this.httpServer = http.createServer(app.handler);
|