@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/cli.cjs
CHANGED
|
@@ -1530,6 +1530,15 @@ function loadPublicUrl() {
|
|
|
1530
1530
|
}
|
|
1531
1531
|
return void 0;
|
|
1532
1532
|
}
|
|
1533
|
+
function loadBrowserCors() {
|
|
1534
|
+
try {
|
|
1535
|
+
const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
|
|
1536
|
+
const match2 = content.match(/browser_cors:\s*(.+)/);
|
|
1537
|
+
if (match2?.[1]) return match2[1].trim();
|
|
1538
|
+
} catch {
|
|
1539
|
+
}
|
|
1540
|
+
return void 0;
|
|
1541
|
+
}
|
|
1533
1542
|
function loadCacheDir() {
|
|
1534
1543
|
try {
|
|
1535
1544
|
const content = (0, import_fs.readFileSync)(configFile(), "utf-8");
|
|
@@ -135802,25 +135811,55 @@ var authMiddleware = (deps) => async (c, next) => {
|
|
|
135802
135811
|
};
|
|
135803
135812
|
|
|
135804
135813
|
// src/api/middleware/cors.middleware.ts
|
|
135805
|
-
var
|
|
135814
|
+
var DEFAULT_DEV_ORIGINS = [
|
|
135806
135815
|
"http://localhost:8081",
|
|
135807
135816
|
"http://localhost:19006",
|
|
135808
135817
|
"http://localhost:3000"
|
|
135809
|
-
]
|
|
135810
|
-
|
|
135811
|
-
|
|
135812
|
-
const
|
|
135813
|
-
|
|
135814
|
-
|
|
135815
|
-
|
|
135816
|
-
|
|
135817
|
-
|
|
135818
|
-
|
|
135819
|
-
|
|
135820
|
-
|
|
135821
|
-
|
|
135822
|
-
|
|
135823
|
-
|
|
135818
|
+
];
|
|
135819
|
+
function resolveAllowedOrigins(raw2) {
|
|
135820
|
+
if (!raw2) return null;
|
|
135821
|
+
const trimmed = raw2.trim();
|
|
135822
|
+
const lower = trimmed.toLowerCase();
|
|
135823
|
+
if (lower === "0" || lower === "false" || lower === "no" || lower === "off" || trimmed === "") {
|
|
135824
|
+
return null;
|
|
135825
|
+
}
|
|
135826
|
+
const origins = new Set(DEFAULT_DEV_ORIGINS);
|
|
135827
|
+
if (!["1", "true", "yes", "on"].includes(lower)) {
|
|
135828
|
+
for (const o of trimmed.split(",")) {
|
|
135829
|
+
const origin = o.trim();
|
|
135830
|
+
if (origin) origins.add(origin);
|
|
135831
|
+
}
|
|
135832
|
+
}
|
|
135833
|
+
return origins;
|
|
135834
|
+
}
|
|
135835
|
+
var corsMiddleware = (configValue) => {
|
|
135836
|
+
const allowedOrigins = resolveAllowedOrigins(
|
|
135837
|
+
process.env.THREADBASE_ALLOW_BROWSER_CORS ?? configValue
|
|
135838
|
+
);
|
|
135839
|
+
return async (c, next) => {
|
|
135840
|
+
const origin = c.req.header("origin");
|
|
135841
|
+
const allowedOrigin = allowedOrigins && origin && allowedOrigins.has(origin) ? origin : null;
|
|
135842
|
+
if (allowedOrigin) {
|
|
135843
|
+
const raw2 = c.env.outgoing;
|
|
135844
|
+
raw2.setHeader("Access-Control-Allow-Origin", allowedOrigin);
|
|
135845
|
+
raw2.setHeader("Vary", "Origin");
|
|
135846
|
+
raw2.setHeader("Access-Control-Allow-Methods", "GET, POST, PATCH, OPTIONS");
|
|
135847
|
+
raw2.setHeader("Access-Control-Allow-Headers", "Authorization, Content-Type, If-None-Match");
|
|
135848
|
+
raw2.setHeader("Access-Control-Expose-Headers", "ETag");
|
|
135849
|
+
c.res.headers.set("Access-Control-Allow-Origin", allowedOrigin);
|
|
135850
|
+
c.res.headers.set("Vary", "Origin");
|
|
135851
|
+
c.res.headers.set("Access-Control-Allow-Methods", "GET, POST, PATCH, OPTIONS");
|
|
135852
|
+
c.res.headers.set(
|
|
135853
|
+
"Access-Control-Allow-Headers",
|
|
135854
|
+
"Authorization, Content-Type, If-None-Match"
|
|
135855
|
+
);
|
|
135856
|
+
c.res.headers.set("Access-Control-Expose-Headers", "ETag");
|
|
135857
|
+
}
|
|
135858
|
+
if (c.req.method === "OPTIONS") {
|
|
135859
|
+
return c.newResponse(null, allowedOrigin ? 204 : 403);
|
|
135860
|
+
}
|
|
135861
|
+
await next();
|
|
135862
|
+
};
|
|
135824
135863
|
};
|
|
135825
135864
|
|
|
135826
135865
|
// src/api/middleware/error.middleware.ts
|
|
@@ -136317,7 +136356,7 @@ var createHonoApp = (deps, upgradeWebSocket) => {
|
|
|
136317
136356
|
event: "http.request"
|
|
136318
136357
|
});
|
|
136319
136358
|
});
|
|
136320
|
-
app.use("*", corsMiddleware());
|
|
136359
|
+
app.use("*", corsMiddleware(deps.browserCors));
|
|
136321
136360
|
app.use("*", authMiddleware(deps));
|
|
136322
136361
|
app.onError(errorMiddleware);
|
|
136323
136362
|
app.route("/healthz", createHealthRoutes());
|
|
@@ -142164,6 +142203,7 @@ var StreamerServer = class {
|
|
|
142164
142203
|
disableDb = false;
|
|
142165
142204
|
browseRoot = null;
|
|
142166
142205
|
publicUrl = null;
|
|
142206
|
+
browserCors;
|
|
142167
142207
|
pairTokens = new PairTokenStore();
|
|
142168
142208
|
exchangeAttempts = /* @__PURE__ */ new Map();
|
|
142169
142209
|
sessionStartAttempts = /* @__PURE__ */ new Map();
|
|
@@ -142249,6 +142289,7 @@ var StreamerServer = class {
|
|
|
142249
142289
|
this.log.warn(`Warning: ${result.error}`, { error: result.error });
|
|
142250
142290
|
}
|
|
142251
142291
|
}
|
|
142292
|
+
this.browserCors = config2.browserCors ?? loadBrowserCors();
|
|
142252
142293
|
this.sessionStore = new SessionStore();
|
|
142253
142294
|
this.wsHub = new WSHub();
|
|
142254
142295
|
this.fileWatcher = new ConversationWatcher({
|
|
@@ -142403,6 +142444,7 @@ var StreamerServer = class {
|
|
|
142403
142444
|
rotateApiKey: () => this.rotateApiKey(),
|
|
142404
142445
|
publicUrl: this.publicUrl,
|
|
142405
142446
|
browseRoot: this.browseRoot,
|
|
142447
|
+
browserCors: this.browserCors,
|
|
142406
142448
|
ptyManager: this.ptyManager,
|
|
142407
142449
|
sessionStore: this.sessionStore,
|
|
142408
142450
|
wsHub: this.wsHub,
|