@threadbase-sh/streamer 1.25.0 → 1.26.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/dist/cli.cjs +59 -17
- package/dist/cli.cjs.map +1 -1
- package/dist/index.cjs +59 -17
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +59 -17
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -375,6 +375,15 @@ function loadPublicUrl() {
|
|
|
375
375
|
}
|
|
376
376
|
return void 0;
|
|
377
377
|
}
|
|
378
|
+
function loadBrowserCors() {
|
|
379
|
+
try {
|
|
380
|
+
const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
|
|
381
|
+
const match = content.match(/browser_cors:\s*(.+)/);
|
|
382
|
+
if (match?.[1]) return match[1].trim();
|
|
383
|
+
} catch {
|
|
384
|
+
}
|
|
385
|
+
return void 0;
|
|
386
|
+
}
|
|
378
387
|
function loadCacheDir() {
|
|
379
388
|
try {
|
|
380
389
|
const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
|
|
@@ -2612,25 +2621,55 @@ var authMiddleware = (deps) => async (c, next) => {
|
|
|
2612
2621
|
};
|
|
2613
2622
|
|
|
2614
2623
|
// src/api/middleware/cors.middleware.ts
|
|
2615
|
-
var
|
|
2624
|
+
var DEFAULT_DEV_ORIGINS = [
|
|
2616
2625
|
"http://localhost:8081",
|
|
2617
2626
|
"http://localhost:19006",
|
|
2618
2627
|
"http://localhost:3000"
|
|
2619
|
-
]
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
const
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2628
|
+
];
|
|
2629
|
+
function resolveAllowedOrigins(raw) {
|
|
2630
|
+
if (!raw) return null;
|
|
2631
|
+
const trimmed = raw.trim();
|
|
2632
|
+
const lower = trimmed.toLowerCase();
|
|
2633
|
+
if (lower === "0" || lower === "false" || lower === "no" || lower === "off" || trimmed === "") {
|
|
2634
|
+
return null;
|
|
2635
|
+
}
|
|
2636
|
+
const origins = new Set(DEFAULT_DEV_ORIGINS);
|
|
2637
|
+
if (!["1", "true", "yes", "on"].includes(lower)) {
|
|
2638
|
+
for (const o of trimmed.split(",")) {
|
|
2639
|
+
const origin = o.trim();
|
|
2640
|
+
if (origin) origins.add(origin);
|
|
2641
|
+
}
|
|
2642
|
+
}
|
|
2643
|
+
return origins;
|
|
2644
|
+
}
|
|
2645
|
+
var corsMiddleware = (configValue) => {
|
|
2646
|
+
const allowedOrigins = resolveAllowedOrigins(
|
|
2647
|
+
process.env.THREADBASE_ALLOW_BROWSER_CORS ?? configValue
|
|
2648
|
+
);
|
|
2649
|
+
return async (c, next) => {
|
|
2650
|
+
const origin = c.req.header("origin");
|
|
2651
|
+
const allowedOrigin = allowedOrigins && origin && allowedOrigins.has(origin) ? origin : null;
|
|
2652
|
+
if (allowedOrigin) {
|
|
2653
|
+
const raw = c.env.outgoing;
|
|
2654
|
+
raw.setHeader("Access-Control-Allow-Origin", allowedOrigin);
|
|
2655
|
+
raw.setHeader("Vary", "Origin");
|
|
2656
|
+
raw.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, OPTIONS");
|
|
2657
|
+
raw.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type, If-None-Match");
|
|
2658
|
+
raw.setHeader("Access-Control-Expose-Headers", "ETag");
|
|
2659
|
+
c.res.headers.set("Access-Control-Allow-Origin", allowedOrigin);
|
|
2660
|
+
c.res.headers.set("Vary", "Origin");
|
|
2661
|
+
c.res.headers.set("Access-Control-Allow-Methods", "GET, POST, PATCH, OPTIONS");
|
|
2662
|
+
c.res.headers.set(
|
|
2663
|
+
"Access-Control-Allow-Headers",
|
|
2664
|
+
"Authorization, Content-Type, If-None-Match"
|
|
2665
|
+
);
|
|
2666
|
+
c.res.headers.set("Access-Control-Expose-Headers", "ETag");
|
|
2667
|
+
}
|
|
2668
|
+
if (c.req.method === "OPTIONS") {
|
|
2669
|
+
return c.newResponse(null, allowedOrigin ? 204 : 403);
|
|
2670
|
+
}
|
|
2671
|
+
await next();
|
|
2672
|
+
};
|
|
2634
2673
|
};
|
|
2635
2674
|
|
|
2636
2675
|
// src/api/middleware/error.middleware.ts
|
|
@@ -3045,7 +3084,7 @@ var createHonoApp = (deps, upgradeWebSocket) => {
|
|
|
3045
3084
|
event: "http.request"
|
|
3046
3085
|
});
|
|
3047
3086
|
});
|
|
3048
|
-
app.use("*", corsMiddleware());
|
|
3087
|
+
app.use("*", corsMiddleware(deps.browserCors));
|
|
3049
3088
|
app.use("*", authMiddleware(deps));
|
|
3050
3089
|
app.onError(errorMiddleware);
|
|
3051
3090
|
app.route("/healthz", createHealthRoutes());
|
|
@@ -5101,6 +5140,7 @@ var StreamerServer = class {
|
|
|
5101
5140
|
disableDb = false;
|
|
5102
5141
|
browseRoot = null;
|
|
5103
5142
|
publicUrl = null;
|
|
5143
|
+
browserCors;
|
|
5104
5144
|
pairTokens = new PairTokenStore();
|
|
5105
5145
|
exchangeAttempts = /* @__PURE__ */ new Map();
|
|
5106
5146
|
sessionStartAttempts = /* @__PURE__ */ new Map();
|
|
@@ -5186,6 +5226,7 @@ var StreamerServer = class {
|
|
|
5186
5226
|
this.log.warn(`Warning: ${result.error}`, { error: result.error });
|
|
5187
5227
|
}
|
|
5188
5228
|
}
|
|
5229
|
+
this.browserCors = config.browserCors ?? loadBrowserCors();
|
|
5189
5230
|
this.sessionStore = new SessionStore();
|
|
5190
5231
|
this.wsHub = new WSHub();
|
|
5191
5232
|
this.fileWatcher = new ConversationWatcher({
|
|
@@ -5340,6 +5381,7 @@ var StreamerServer = class {
|
|
|
5340
5381
|
rotateApiKey: () => this.rotateApiKey(),
|
|
5341
5382
|
publicUrl: this.publicUrl,
|
|
5342
5383
|
browseRoot: this.browseRoot,
|
|
5384
|
+
browserCors: this.browserCors,
|
|
5343
5385
|
ptyManager: this.ptyManager,
|
|
5344
5386
|
sessionStore: this.sessionStore,
|
|
5345
5387
|
wsHub: this.wsHub,
|