socket-function 0.75.0 → 0.76.0

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/SocketFunction.ts CHANGED
@@ -419,8 +419,9 @@ export class SocketFunction {
419
419
  if (isNode()) {
420
420
  throw new Error("Cannot get browser nodeId on server");
421
421
  }
422
- if (globalThis.BOOTED_EDGE_NODE) {
423
- return globalThis.BOOTED_EDGE_NODE.host;
422
+ let edgeNode = getBootedEdgeNode();
423
+ if (edgeNode) {
424
+ return edgeNode.host;
424
425
  }
425
426
  return SocketFunction.connect({ address: location.hostname, port: +location.port || 443 });
426
427
  }
@@ -433,14 +434,9 @@ export class SocketFunction {
433
434
  }
434
435
  }
435
436
 
436
-
437
- declare global {
438
- var BOOTED_EDGE_NODE: EdgeNodeConfig | undefined;
437
+ function getBootedEdgeNode() {
438
+ return (globalThis as any).BOOTED_EDGE_NODE as { host: string } | undefined;
439
439
  }
440
- type EdgeNodeConfig = {
441
- // EX: 127-0-0-1.example.com:3334
442
- host: string;
443
- };
444
440
 
445
441
 
446
442
  let socketContextSeqNum = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "socket-function",
3
- "version": "0.75.0",
3
+ "version": "0.76.0",
4
4
  "main": "index.js",
5
5
  "license": "MIT",
6
6
  "dependencies": {
@@ -46,7 +46,9 @@ export type SocketServerConfig = (
46
46
  // may be, "querysub.com", for example), use ["letx.ca"]
47
47
  allowHostnames?: string[];
48
48
 
49
- /** If the SNI matches this domain, we use a different key/cert. */
49
+ /** If the SNI matches this domain, we use a different key/cert.
50
+ * We remove subdomains until we find a match
51
+ */
50
52
  SNICerts?: {
51
53
  [domain: string]: Watchable<https.ServerOptions>;
52
54
  };
@@ -214,14 +216,16 @@ export async function startSocketServer(
214
216
  console.warn(`No SNI found in TLS hello from ${debug}, using main server. Packets ${packetCount}`);
215
217
  console.log(buffer.toString("base64"));
216
218
  }
219
+ let originalSNI = sni;
220
+ // Remove subdomains until we can find a domain
221
+ while (!sniServers.has(sni)) {
222
+ let parts = sni.split(".");
223
+ if (parts.length <= 2) break;
224
+ sni = parts.slice(1).join(".");
225
+ }
217
226
 
218
227
  if (!sniServers.has(sni)) {
219
- if (sni) {
220
- sni = sni.split(".").slice(-2).join(".");
221
- }
222
- if (!sniServers.has(sni)) {
223
- console.warn(`No SNI server found for ${sni}, using main server.`);
224
- }
228
+ console.warn(`No SNI server found for ${originalSNI}, using main server. SNI candidates ${Array.from(sniServers.keys()).join(", ")}`);
225
229
  }
226
230
  server = sniServers.get(sni) || mainHTTPSServer;
227
231
  }