elit 3.4.9 → 3.5.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.
- package/README.md +98 -6
- package/dist/build.d.mts +1 -1
- package/dist/cli.js +539 -111
- package/dist/config.d.mts +9 -2
- package/dist/config.d.ts +7 -0
- package/dist/config.d.ts.map +1 -1
- package/dist/config.js.map +1 -1
- package/dist/config.mjs.map +1 -1
- package/dist/coverage.d.mts +1 -1
- package/dist/desktop-cli.d.ts.map +1 -1
- package/dist/http.d.ts.map +1 -1
- package/dist/http.js +5 -4
- package/dist/http.js.map +1 -1
- package/dist/http.mjs +5 -4
- package/dist/http.mjs.map +1 -1
- package/dist/https.js +5 -4
- package/dist/https.js.map +1 -1
- package/dist/https.mjs +5 -4
- package/dist/https.mjs.map +1 -1
- package/dist/index.d.mts +1 -1
- package/dist/index.js +20 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -1
- package/dist/index.mjs.map +1 -1
- package/dist/native.js +20 -1
- package/dist/native.js.map +1 -1
- package/dist/native.mjs +20 -1
- package/dist/native.mjs.map +1 -1
- package/dist/{server-DpnTyF7I.d.mts → server--YFoC6ln.d.mts} +27 -0
- package/dist/{server-BU71N4fk.d.ts → server-DacsdjFJ.d.ts} +27 -0
- package/dist/server.d.mts +1 -1
- package/dist/server.d.ts.map +1 -1
- package/dist/server.js +141 -52
- package/dist/server.js.map +1 -1
- package/dist/server.mjs +141 -52
- package/dist/server.mjs.map +1 -1
- package/dist/state.d.ts.map +1 -1
- package/dist/state.js +20 -1
- package/dist/state.js.map +1 -1
- package/dist/state.mjs +20 -1
- package/dist/state.mjs.map +1 -1
- package/dist/types.d.mts +28 -1
- package/dist/types.d.ts +27 -0
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/wapk-cli.d.ts +15 -4
- package/dist/wapk-cli.d.ts.map +1 -1
- package/dist/ws.d.mts +1 -1
- package/dist/ws.d.ts +1 -1
- package/dist/ws.d.ts.map +1 -1
- package/dist/ws.js +9 -4
- package/dist/ws.js.map +1 -1
- package/dist/ws.mjs +9 -4
- package/dist/ws.mjs.map +1 -1
- package/dist/wss.js +14 -8
- package/dist/wss.js.map +1 -1
- package/dist/wss.mjs +14 -8
- package/dist/wss.mjs.map +1 -1
- package/package.json +1 -1
- package/src/cli.ts +18 -0
- package/src/config.ts +8 -0
- package/src/desktop-cli.ts +19 -1
- package/src/http.ts +5 -4
- package/src/server.ts +182 -56
- package/src/state.ts +25 -1
- package/src/types.ts +30 -0
- package/src/wapk-cli.ts +451 -52
- package/src/ws.ts +12 -5
|
@@ -35,6 +35,27 @@ interface RefObject {
|
|
|
35
35
|
}
|
|
36
36
|
type Router = ServerRouter;
|
|
37
37
|
type StateManager$1 = StateManager;
|
|
38
|
+
type WebSocketConnection = WebSocket;
|
|
39
|
+
type WebSocketRequest = IncomingMessage;
|
|
40
|
+
interface WebSocketEndpointContext {
|
|
41
|
+
/** Accepted WebSocket connection */
|
|
42
|
+
ws: WebSocketConnection;
|
|
43
|
+
/** Upgrade request metadata */
|
|
44
|
+
req: WebSocketRequest;
|
|
45
|
+
/** Matched request path without query string */
|
|
46
|
+
path: string;
|
|
47
|
+
/** Parsed query string values */
|
|
48
|
+
query: Record<string, string>;
|
|
49
|
+
/** Request headers */
|
|
50
|
+
headers: Record<string, string | string[] | undefined>;
|
|
51
|
+
}
|
|
52
|
+
type WebSocketEndpointHandler = (ctx: WebSocketEndpointContext) => void | Promise<void>;
|
|
53
|
+
interface WebSocketEndpointConfig {
|
|
54
|
+
/** Path to listen for WebSocket upgrades (e.g., '/ws', '/chat') */
|
|
55
|
+
path: string;
|
|
56
|
+
/** Connection handler invoked after a successful WebSocket upgrade */
|
|
57
|
+
handler: WebSocketEndpointHandler;
|
|
58
|
+
}
|
|
38
59
|
interface ClientConfig {
|
|
39
60
|
/** Root directory to serve files from */
|
|
40
61
|
root: string;
|
|
@@ -54,6 +75,8 @@ interface ClientConfig {
|
|
|
54
75
|
worker?: WorkerConfig[];
|
|
55
76
|
/** API router for REST endpoints specific to this client */
|
|
56
77
|
api?: Router;
|
|
78
|
+
/** WebSocket endpoints specific to this client */
|
|
79
|
+
ws?: WebSocketEndpointConfig[];
|
|
57
80
|
/** Server mode: 'dev' uses source files, 'preview' uses built files (default: 'dev') */
|
|
58
81
|
mode?: 'dev' | 'preview';
|
|
59
82
|
}
|
|
@@ -108,6 +131,8 @@ interface DevServerOptions {
|
|
|
108
131
|
logging?: boolean;
|
|
109
132
|
/** API router for REST endpoints */
|
|
110
133
|
api?: Router;
|
|
134
|
+
/** WebSocket endpoints */
|
|
135
|
+
ws?: WebSocketEndpointConfig[];
|
|
111
136
|
/** SSR render function - returns HTML VNode or string */
|
|
112
137
|
ssr?: () => Child | string;
|
|
113
138
|
/** Proxy configuration for API requests */
|
|
@@ -203,6 +228,8 @@ interface PreviewOptions {
|
|
|
203
228
|
logging?: boolean;
|
|
204
229
|
/** API router for REST endpoints */
|
|
205
230
|
api?: Router;
|
|
231
|
+
/** WebSocket endpoints */
|
|
232
|
+
ws?: WebSocketEndpointConfig[];
|
|
206
233
|
/** SSR render function - returns HTML VNode or string */
|
|
207
234
|
ssr?: () => Child | string;
|
|
208
235
|
/** Proxy configuration for API requests */
|
|
@@ -35,6 +35,27 @@ interface RefObject {
|
|
|
35
35
|
}
|
|
36
36
|
type Router = ServerRouter;
|
|
37
37
|
type StateManager$1 = StateManager;
|
|
38
|
+
type WebSocketConnection = WebSocket;
|
|
39
|
+
type WebSocketRequest = IncomingMessage;
|
|
40
|
+
interface WebSocketEndpointContext {
|
|
41
|
+
/** Accepted WebSocket connection */
|
|
42
|
+
ws: WebSocketConnection;
|
|
43
|
+
/** Upgrade request metadata */
|
|
44
|
+
req: WebSocketRequest;
|
|
45
|
+
/** Matched request path without query string */
|
|
46
|
+
path: string;
|
|
47
|
+
/** Parsed query string values */
|
|
48
|
+
query: Record<string, string>;
|
|
49
|
+
/** Request headers */
|
|
50
|
+
headers: Record<string, string | string[] | undefined>;
|
|
51
|
+
}
|
|
52
|
+
type WebSocketEndpointHandler = (ctx: WebSocketEndpointContext) => void | Promise<void>;
|
|
53
|
+
interface WebSocketEndpointConfig {
|
|
54
|
+
/** Path to listen for WebSocket upgrades (e.g., '/ws', '/chat') */
|
|
55
|
+
path: string;
|
|
56
|
+
/** Connection handler invoked after a successful WebSocket upgrade */
|
|
57
|
+
handler: WebSocketEndpointHandler;
|
|
58
|
+
}
|
|
38
59
|
interface ClientConfig {
|
|
39
60
|
/** Root directory to serve files from */
|
|
40
61
|
root: string;
|
|
@@ -54,6 +75,8 @@ interface ClientConfig {
|
|
|
54
75
|
worker?: WorkerConfig[];
|
|
55
76
|
/** API router for REST endpoints specific to this client */
|
|
56
77
|
api?: Router;
|
|
78
|
+
/** WebSocket endpoints specific to this client */
|
|
79
|
+
ws?: WebSocketEndpointConfig[];
|
|
57
80
|
/** Server mode: 'dev' uses source files, 'preview' uses built files (default: 'dev') */
|
|
58
81
|
mode?: 'dev' | 'preview';
|
|
59
82
|
}
|
|
@@ -108,6 +131,8 @@ interface DevServerOptions {
|
|
|
108
131
|
logging?: boolean;
|
|
109
132
|
/** API router for REST endpoints */
|
|
110
133
|
api?: Router;
|
|
134
|
+
/** WebSocket endpoints */
|
|
135
|
+
ws?: WebSocketEndpointConfig[];
|
|
111
136
|
/** SSR render function - returns HTML VNode or string */
|
|
112
137
|
ssr?: () => Child | string;
|
|
113
138
|
/** Proxy configuration for API requests */
|
|
@@ -203,6 +228,8 @@ interface PreviewOptions {
|
|
|
203
228
|
logging?: boolean;
|
|
204
229
|
/** API router for REST endpoints */
|
|
205
230
|
api?: Router;
|
|
231
|
+
/** WebSocket endpoints */
|
|
232
|
+
ws?: WebSocketEndpointConfig[];
|
|
206
233
|
/** SSR render function - returns HTML VNode or string */
|
|
207
234
|
ssr?: () => Child | string;
|
|
208
235
|
/** Proxy configuration for API requests */
|
package/dist/server.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import './http.mjs';
|
|
2
2
|
import './ws.mjs';
|
|
3
|
-
export { E as ElitRequest, c as ElitResponse, H as HttpMethod, M as Middleware, S as ServerRouteContext, d as ServerRouteHandler, e as ServerRouter, f as SharedState, g as SharedStateOptions, h as StateChangeHandler, i as StateManager, j as bodyLimit, k as cacheControl, l as clearImportMapCache, m as compress, n as cors, o as createDevServer, p as createProxyHandler, q as errorHandler, r as html, s as json, t as logger, u as rateLimit, v as security, w as status, x as text } from './server
|
|
3
|
+
export { E as ElitRequest, c as ElitResponse, H as HttpMethod, M as Middleware, S as ServerRouteContext, d as ServerRouteHandler, e as ServerRouter, f as SharedState, g as SharedStateOptions, h as StateChangeHandler, i as StateManager, j as bodyLimit, k as cacheControl, l as clearImportMapCache, m as compress, n as cors, o as createDevServer, p as createProxyHandler, q as errorHandler, r as html, s as json, t as logger, u as rateLimit, v as security, w as status, x as text } from './server--YFoC6ln.mjs';
|
|
4
4
|
import 'node:events';
|
|
5
5
|
import 'events';
|
|
6
6
|
import 'http';
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgB,eAAe,EAAE,cAAc,EAA0B,MAAM,QAAQ,CAAC;AAE/F,OAAO,EAAmB,SAAS,
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAgB,eAAe,EAAE,cAAc,EAA0B,MAAM,QAAQ,CAAC;AAE/F,OAAO,EAAmB,SAAS,EAA2B,MAAM,MAAM,CAAC;AAM3E,OAAO,KAAK,EAAE,gBAAgB,EAAE,SAAS,EAA4B,WAAW,EAA2B,MAAM,SAAS,CAAC;AAK3H,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,QAAQ,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AE,MAAM,GAAG,WAAW,CAAC,CAAC,CAAC,GAAG,SAAS;IAI/C,GAAG,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAIzB,MAAM,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO;IAS5B,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,GAAG,IAAI;IAI3C,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,EAAE,SAAS,GAAG,IAAI;IAI7C,cAAc,CAAC,EAAE,EAAE,SAAS,GAAG,IAAI;IAInC,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,IAAI;IAKhD,IAAI,IAAI,MAAM,EAAE;IAIhB,KAAK,IAAI,IAAI;CAId;AA2BD,wBAAgB,eAAe,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CA22BpE"}
|
package/dist/server.js
CHANGED
|
@@ -503,11 +503,12 @@ var init_http = __esm({
|
|
|
503
503
|
},
|
|
504
504
|
fetch: (req) => {
|
|
505
505
|
const urlObj = new URL(req.url);
|
|
506
|
-
const pathname = urlObj.pathname
|
|
506
|
+
const pathname = urlObj.pathname;
|
|
507
|
+
const requestUrl = urlObj.pathname + urlObj.search;
|
|
507
508
|
const upgradeHeader = req.headers.get("upgrade");
|
|
508
509
|
if (upgradeHeader && upgradeHeader.toLowerCase() === "websocket") {
|
|
509
510
|
const matchingWebSocketServer = Array.from(this._bunWebSocketServers).find((wsServer) => {
|
|
510
|
-
return !wsServer.path || wsServer.path ===
|
|
511
|
+
return !wsServer.path || wsServer.path === pathname;
|
|
511
512
|
});
|
|
512
513
|
if (!matchingWebSocketServer) {
|
|
513
514
|
return new Response("WebSocket path not found", { status: 404 });
|
|
@@ -521,7 +522,7 @@ var init_http = __esm({
|
|
|
521
522
|
wsServer: matchingWebSocketServer,
|
|
522
523
|
request: {
|
|
523
524
|
method: req.method,
|
|
524
|
-
url:
|
|
525
|
+
url: requestUrl,
|
|
525
526
|
headers: requestHeaders,
|
|
526
527
|
socket: { remoteAddress: void 0 }
|
|
527
528
|
}
|
|
@@ -539,7 +540,7 @@ var init_http = __esm({
|
|
|
539
540
|
let responseReady = false;
|
|
540
541
|
const incomingMessage = {
|
|
541
542
|
method: req.method,
|
|
542
|
-
url:
|
|
543
|
+
url: requestUrl,
|
|
543
544
|
headers: req.headers,
|
|
544
545
|
httpVersion: "1.1",
|
|
545
546
|
rawHeaders: [],
|
|
@@ -54710,6 +54711,10 @@ function createNativeWebSocket(url, protocols) {
|
|
|
54710
54711
|
}
|
|
54711
54712
|
return new globalThis.WebSocket(url, protocols);
|
|
54712
54713
|
}
|
|
54714
|
+
function getRequestPath(url) {
|
|
54715
|
+
const [pathname = "/"] = (url || "/").split("?");
|
|
54716
|
+
return pathname || "/";
|
|
54717
|
+
}
|
|
54713
54718
|
var WebSocket = class extends import_events2.EventEmitter {
|
|
54714
54719
|
constructor(address, protocols, _options) {
|
|
54715
54720
|
super();
|
|
@@ -54806,7 +54811,7 @@ var WebSocketServer = class extends import_events2.EventEmitter {
|
|
|
54806
54811
|
this.clients = /* @__PURE__ */ new Set();
|
|
54807
54812
|
this._ownsHttpServer = false;
|
|
54808
54813
|
this.options = options || {};
|
|
54809
|
-
this.path = options?.path
|
|
54814
|
+
this.path = options?.path;
|
|
54810
54815
|
if (runtime === "node") {
|
|
54811
54816
|
if (options?.server) {
|
|
54812
54817
|
this._httpServer = options.server;
|
|
@@ -54833,8 +54838,9 @@ var WebSocketServer = class extends import_events2.EventEmitter {
|
|
|
54833
54838
|
}
|
|
54834
54839
|
_setupUpgradeHandler() {
|
|
54835
54840
|
this._httpServer.on("upgrade", (request3, socket, head) => {
|
|
54836
|
-
|
|
54837
|
-
|
|
54841
|
+
const requestPath = getRequestPath(request3.url);
|
|
54842
|
+
console.log("[WebSocket] Upgrade request:", requestPath, "Expected:", this.path || "(any)");
|
|
54843
|
+
if (this.path && requestPath !== this.path) {
|
|
54838
54844
|
console.log("[WebSocket] Path mismatch, ignoring");
|
|
54839
54845
|
return;
|
|
54840
54846
|
}
|
|
@@ -55078,7 +55084,7 @@ var WebSocketServer = class extends import_events2.EventEmitter {
|
|
|
55078
55084
|
* Check if server should handle request
|
|
55079
55085
|
*/
|
|
55080
55086
|
shouldHandle(request3) {
|
|
55081
|
-
if (this.path && request3.url !== this.path) {
|
|
55087
|
+
if (this.path && getRequestPath(request3.url) !== this.path) {
|
|
55082
55088
|
return false;
|
|
55083
55089
|
}
|
|
55084
55090
|
return true;
|
|
@@ -56629,7 +56635,8 @@ var createElitImportMap = async (rootDir, basePath = "", mode = "dev") => {
|
|
|
56629
56635
|
const allImports = { ...externalImports, ...elitImports };
|
|
56630
56636
|
return `<script type="importmap">${JSON.stringify({ imports: allImports }, null, 2)}</script>`;
|
|
56631
56637
|
};
|
|
56632
|
-
var
|
|
56638
|
+
var ELIT_INTERNAL_WS_PATH = "/__elit_ws";
|
|
56639
|
+
var createHMRScript = (port) => `<script>(function(){let ws;let retries=0;let maxRetries=5;const protocol=window.location.protocol==='https:'?'wss://':'ws://';function connect(){ws=new WebSocket(protocol+window.location.hostname+':${port}${ELIT_INTERNAL_WS_PATH}');ws.onopen=()=>{console.log('[Elit HMR] Connected');retries=0};ws.onmessage=(e)=>{const d=JSON.parse(e.data);if(d.type==='update'){console.log('[Elit HMR] File updated:',d.path);window.location.reload()}else if(d.type==='reload'){console.log('[Elit HMR] Reloading...');window.location.reload()}else if(d.type==='error')console.error('[Elit HMR] Error:',d.error)};ws.onclose=()=>{if(retries<maxRetries){retries++;setTimeout(connect,1000*retries)}else if(retries===maxRetries){console.log('[Elit HMR] Connection closed. Start dev server to reconnect.')}};ws.onerror=()=>{ws.close()}}connect()})();</script>`;
|
|
56633
56640
|
var rewriteRelativePaths = (html2, basePath) => {
|
|
56634
56641
|
if (!basePath) return html2;
|
|
56635
56642
|
html2 = html2.replace(/(<script[^>]+src=["'])(?!https?:\/\/|\/)(\.\/)?([^"']+)(["'])/g, `$1${basePath}/$3$4`);
|
|
@@ -56637,6 +56644,52 @@ var rewriteRelativePaths = (html2, basePath) => {
|
|
|
56637
56644
|
return html2;
|
|
56638
56645
|
};
|
|
56639
56646
|
var normalizeBasePath = (basePath) => basePath && basePath !== "/" ? basePath : "";
|
|
56647
|
+
var normalizeWebSocketPath = (path) => {
|
|
56648
|
+
let normalizedPath = path.trim();
|
|
56649
|
+
if (!normalizedPath) {
|
|
56650
|
+
return "/";
|
|
56651
|
+
}
|
|
56652
|
+
if (!normalizedPath.startsWith("/")) {
|
|
56653
|
+
normalizedPath = `/${normalizedPath}`;
|
|
56654
|
+
}
|
|
56655
|
+
if (normalizedPath.length > 1 && normalizedPath.endsWith("/")) {
|
|
56656
|
+
normalizedPath = normalizedPath.slice(0, -1);
|
|
56657
|
+
}
|
|
56658
|
+
return normalizedPath;
|
|
56659
|
+
};
|
|
56660
|
+
var getRequestPath2 = (url) => {
|
|
56661
|
+
const [pathname = "/"] = url.split("?");
|
|
56662
|
+
return pathname || "/";
|
|
56663
|
+
};
|
|
56664
|
+
var parseRequestQuery = (url) => {
|
|
56665
|
+
const query = {};
|
|
56666
|
+
const queryString = url.split("?")[1];
|
|
56667
|
+
if (!queryString) {
|
|
56668
|
+
return query;
|
|
56669
|
+
}
|
|
56670
|
+
for (const entry of queryString.split("&")) {
|
|
56671
|
+
if (!entry) {
|
|
56672
|
+
continue;
|
|
56673
|
+
}
|
|
56674
|
+
const [rawKey, rawValue = ""] = entry.split("=");
|
|
56675
|
+
if (!rawKey) {
|
|
56676
|
+
continue;
|
|
56677
|
+
}
|
|
56678
|
+
query[decodeURIComponent(rawKey)] = decodeURIComponent(rawValue);
|
|
56679
|
+
}
|
|
56680
|
+
return query;
|
|
56681
|
+
};
|
|
56682
|
+
var normalizeWebSocketEndpoints = (endpoints, basePath = "") => {
|
|
56683
|
+
const normalizedBasePath = normalizeBasePath(basePath);
|
|
56684
|
+
return (endpoints || []).map((endpoint) => {
|
|
56685
|
+
const normalizedPath = normalizeWebSocketPath(endpoint.path);
|
|
56686
|
+
const fullPath = !normalizedBasePath ? normalizedPath : normalizedPath === normalizedBasePath || normalizedPath.startsWith(`${normalizedBasePath}/`) ? normalizedPath : normalizedPath === "/" ? normalizedBasePath : `${normalizedBasePath}${normalizedPath}`;
|
|
56687
|
+
return {
|
|
56688
|
+
path: fullPath,
|
|
56689
|
+
handler: endpoint.handler
|
|
56690
|
+
};
|
|
56691
|
+
});
|
|
56692
|
+
};
|
|
56640
56693
|
var requestAcceptsGzip = (acceptEncoding) => {
|
|
56641
56694
|
if (Array.isArray(acceptEncoding)) {
|
|
56642
56695
|
return acceptEncoding.some((value) => /\bgzip\b/i.test(value));
|
|
@@ -57183,7 +57236,8 @@ function createDevServer(options) {
|
|
|
57183
57236
|
if (config.mode === "dev") {
|
|
57184
57237
|
clearImportMapCache();
|
|
57185
57238
|
}
|
|
57186
|
-
const
|
|
57239
|
+
const usesClientArray = Boolean(config.clients?.length);
|
|
57240
|
+
const clientsToNormalize = usesClientArray ? config.clients : config.root ? [{ root: config.root, basePath: config.basePath || "", index: config.index, ssr: config.ssr, api: config.api, proxy: config.proxy, ws: config.ws, mode: config.mode }] : null;
|
|
57187
57241
|
if (!clientsToNormalize) throw new Error('DevServerOptions must include either "clients" array or "root" directory');
|
|
57188
57242
|
const normalizedClients = clientsToNormalize.map((client) => {
|
|
57189
57243
|
let basePath = client.basePath || "";
|
|
@@ -57205,10 +57259,23 @@ function createDevServer(options) {
|
|
|
57205
57259
|
index: indexPath,
|
|
57206
57260
|
ssr: client.ssr,
|
|
57207
57261
|
api: client.api,
|
|
57262
|
+
ws: normalizeWebSocketEndpoints(client.ws, basePath),
|
|
57208
57263
|
proxyHandler: client.proxy ? createProxyHandler(client.proxy) : void 0,
|
|
57209
57264
|
mode: client.mode || "dev"
|
|
57210
57265
|
};
|
|
57211
57266
|
});
|
|
57267
|
+
const globalWebSocketEndpoints = usesClientArray ? normalizeWebSocketEndpoints(config.ws) : [];
|
|
57268
|
+
const normalizedWebSocketEndpoints = [...normalizedClients.flatMap((client) => client.ws), ...globalWebSocketEndpoints];
|
|
57269
|
+
const seenWebSocketPaths = /* @__PURE__ */ new Set();
|
|
57270
|
+
for (const endpoint of normalizedWebSocketEndpoints) {
|
|
57271
|
+
if (endpoint.path === ELIT_INTERNAL_WS_PATH) {
|
|
57272
|
+
throw new Error(`WebSocket path "${ELIT_INTERNAL_WS_PATH}" is reserved for Elit internals`);
|
|
57273
|
+
}
|
|
57274
|
+
if (seenWebSocketPaths.has(endpoint.path)) {
|
|
57275
|
+
throw new Error(`Duplicate WebSocket endpoint path: ${endpoint.path}`);
|
|
57276
|
+
}
|
|
57277
|
+
seenWebSocketPaths.add(endpoint.path);
|
|
57278
|
+
}
|
|
57212
57279
|
const globalProxyHandler = config.proxy ? createProxyHandler(config.proxy) : null;
|
|
57213
57280
|
const server = createServer(async (req, res) => {
|
|
57214
57281
|
const originalUrl = req.url || "/";
|
|
@@ -57525,8 +57592,7 @@ ${error}`);
|
|
|
57525
57592
|
}
|
|
57526
57593
|
}
|
|
57527
57594
|
if (ext === ".html") {
|
|
57528
|
-
const
|
|
57529
|
-
const hmrScript = config.mode !== "preview" ? createHMRScript(config.port, wsPath) : "";
|
|
57595
|
+
const hmrScript = config.mode !== "preview" ? createHMRScript(config.port) : "";
|
|
57530
57596
|
let html2 = content.toString();
|
|
57531
57597
|
let ssrStyles = "";
|
|
57532
57598
|
if (client.ssr) {
|
|
@@ -57625,7 +57691,7 @@ ${elitImportMap}`;
|
|
|
57625
57691
|
}
|
|
57626
57692
|
const basePath = normalizeBasePath(client.basePath);
|
|
57627
57693
|
html2 = rewriteRelativePaths(html2, basePath);
|
|
57628
|
-
const hmrScript = config.mode !== "preview" ? createHMRScript(config.port
|
|
57694
|
+
const hmrScript = config.mode !== "preview" ? createHMRScript(config.port) : "";
|
|
57629
57695
|
const elitImportMap = await createElitImportMap(client.root, basePath, client.mode);
|
|
57630
57696
|
const modeScript = config.mode === "preview" ? "<script>window.__ELIT_MODE__='preview';</script>\n" : "";
|
|
57631
57697
|
html2 = html2.includes("</head>") ? html2.replace("</head>", `${modeScript}${elitImportMap}</head>`) : html2;
|
|
@@ -57645,49 +57711,73 @@ ${elitImportMap}`;
|
|
|
57645
57711
|
send500(res, "500 SSR Error");
|
|
57646
57712
|
}
|
|
57647
57713
|
}
|
|
57648
|
-
|
|
57649
|
-
|
|
57650
|
-
|
|
57714
|
+
const wss = new WebSocketServer({ server, path: ELIT_INTERNAL_WS_PATH });
|
|
57715
|
+
const webSocketServers = [wss];
|
|
57716
|
+
if (config.logging) {
|
|
57717
|
+
console.log(`[WebSocket] Internal server initialized at ${ELIT_INTERNAL_WS_PATH}`);
|
|
57718
|
+
}
|
|
57719
|
+
wss.on("connection", (ws, req) => {
|
|
57720
|
+
wsClients.add(ws);
|
|
57721
|
+
const message = { type: "connected", timestamp: Date.now() };
|
|
57722
|
+
ws.send(JSON.stringify(message));
|
|
57651
57723
|
if (config.logging) {
|
|
57652
|
-
console.log("[
|
|
57724
|
+
console.log("[WebSocket] Internal client connected from", req.socket.remoteAddress);
|
|
57653
57725
|
}
|
|
57654
|
-
|
|
57655
|
-
|
|
57656
|
-
|
|
57657
|
-
|
|
57658
|
-
|
|
57659
|
-
|
|
57660
|
-
|
|
57661
|
-
ws.on("message", (data) => {
|
|
57662
|
-
try {
|
|
57663
|
-
const msg = JSON.parse(data.toString());
|
|
57664
|
-
if (msg.type === "state:subscribe") {
|
|
57665
|
-
stateManager.subscribe(msg.key, ws);
|
|
57666
|
-
if (config.logging) {
|
|
57667
|
-
console.log(`[State] Client subscribed to "${msg.key}"`);
|
|
57668
|
-
}
|
|
57669
|
-
} else if (msg.type === "state:unsubscribe") {
|
|
57670
|
-
stateManager.unsubscribe(msg.key, ws);
|
|
57671
|
-
if (config.logging) {
|
|
57672
|
-
console.log(`[State] Client unsubscribed from "${msg.key}"`);
|
|
57673
|
-
}
|
|
57674
|
-
} else if (msg.type === "state:change") {
|
|
57675
|
-
stateManager.handleStateChange(msg.key, msg.value);
|
|
57676
|
-
if (config.logging) {
|
|
57677
|
-
console.log(`[State] Client updated "${msg.key}"`);
|
|
57678
|
-
}
|
|
57726
|
+
ws.on("message", (data) => {
|
|
57727
|
+
try {
|
|
57728
|
+
const msg = JSON.parse(data.toString());
|
|
57729
|
+
if (msg.type === "state:subscribe") {
|
|
57730
|
+
stateManager.subscribe(msg.key, ws);
|
|
57731
|
+
if (config.logging) {
|
|
57732
|
+
console.log(`[State] Client subscribed to "${msg.key}"`);
|
|
57679
57733
|
}
|
|
57680
|
-
}
|
|
57734
|
+
} else if (msg.type === "state:unsubscribe") {
|
|
57735
|
+
stateManager.unsubscribe(msg.key, ws);
|
|
57736
|
+
if (config.logging) {
|
|
57737
|
+
console.log(`[State] Client unsubscribed from "${msg.key}"`);
|
|
57738
|
+
}
|
|
57739
|
+
} else if (msg.type === "state:change") {
|
|
57740
|
+
stateManager.handleStateChange(msg.key, msg.value);
|
|
57681
57741
|
if (config.logging) {
|
|
57682
|
-
console.
|
|
57742
|
+
console.log(`[State] Client updated "${msg.key}"`);
|
|
57683
57743
|
}
|
|
57684
57744
|
}
|
|
57685
|
-
})
|
|
57686
|
-
|
|
57687
|
-
|
|
57688
|
-
|
|
57745
|
+
} catch (error) {
|
|
57746
|
+
if (config.logging) {
|
|
57747
|
+
console.error("[WebSocket] Message parse error:", error);
|
|
57748
|
+
}
|
|
57749
|
+
}
|
|
57750
|
+
});
|
|
57751
|
+
ws.on("close", () => {
|
|
57752
|
+
wsClients.delete(ws);
|
|
57753
|
+
stateManager.unsubscribeAll(ws);
|
|
57754
|
+
if (config.logging) {
|
|
57755
|
+
console.log("[WebSocket] Internal client disconnected");
|
|
57756
|
+
}
|
|
57757
|
+
});
|
|
57758
|
+
});
|
|
57759
|
+
for (const endpoint of normalizedWebSocketEndpoints) {
|
|
57760
|
+
const endpointServer = new WebSocketServer({ server, path: endpoint.path });
|
|
57761
|
+
webSocketServers.push(endpointServer);
|
|
57762
|
+
if (config.logging) {
|
|
57763
|
+
console.log(`[WebSocket] Endpoint ready at ${endpoint.path}`);
|
|
57764
|
+
}
|
|
57765
|
+
endpointServer.on("connection", (ws, req) => {
|
|
57766
|
+
const requestUrl = req.url || endpoint.path;
|
|
57767
|
+
const ctx = {
|
|
57768
|
+
ws,
|
|
57769
|
+
req,
|
|
57770
|
+
path: getRequestPath2(requestUrl),
|
|
57771
|
+
query: parseRequestQuery(requestUrl),
|
|
57772
|
+
headers: req.headers
|
|
57773
|
+
};
|
|
57774
|
+
void Promise.resolve(endpoint.handler(ctx)).catch((error) => {
|
|
57689
57775
|
if (config.logging) {
|
|
57690
|
-
console.
|
|
57776
|
+
console.error(`[WebSocket] Endpoint error at ${endpoint.path}:`, error);
|
|
57777
|
+
}
|
|
57778
|
+
try {
|
|
57779
|
+
ws.close(CLOSE_CODES.INTERNAL_ERROR, "Internal Server Error");
|
|
57780
|
+
} catch {
|
|
57691
57781
|
}
|
|
57692
57782
|
});
|
|
57693
57783
|
});
|
|
@@ -57771,9 +57861,8 @@ ${elitImportMap}`;
|
|
|
57771
57861
|
isClosing = true;
|
|
57772
57862
|
if (config.logging) console.log("\n[Server] Shutting down...");
|
|
57773
57863
|
if (watcher) await watcher.close();
|
|
57774
|
-
if (
|
|
57775
|
-
|
|
57776
|
-
wsClients.forEach((client) => client.close());
|
|
57864
|
+
if (webSocketServers.length > 0) {
|
|
57865
|
+
webSocketServers.forEach((wsServer) => wsServer.close());
|
|
57777
57866
|
wsClients.clear();
|
|
57778
57867
|
}
|
|
57779
57868
|
return new Promise((resolve2) => {
|