mirror of
https://github.com/Nezumi-2711/9router.git
synced 2026-09-22 20:00:47 +00:00
Make API key optional for MITM server
- Remove hard exit when ROUTER_API_KEY is missing - Conditionally attach Authorization header only if API_KEY is set - Allow MITM auto-start without requiring an active API key - Fallback to default key when no active key is found Made-with: Cursor
This commit is contained in:
+1
-5
@@ -25,10 +25,6 @@ const DB_FILE = path.join(DATA_DIR, "db.json");
|
|||||||
|
|
||||||
const ENABLE_FILE_LOG = false;
|
const ENABLE_FILE_LOG = false;
|
||||||
|
|
||||||
if (!API_KEY) {
|
|
||||||
err("ROUTER_API_KEY required");
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
const { getCertForDomain } = require("./cert/generate");
|
const { getCertForDomain } = require("./cert/generate");
|
||||||
|
|
||||||
@@ -193,7 +189,7 @@ async function intercept(req, res, bodyBuffer, mappedModel) {
|
|||||||
method: "POST",
|
method: "POST",
|
||||||
headers: {
|
headers: {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
"Authorization": `Bearer ${API_KEY}`
|
...(API_KEY && { "Authorization": `Bearer ${API_KEY}` })
|
||||||
},
|
},
|
||||||
body: JSON.stringify(body)
|
body: JSON.stringify(body)
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -116,13 +116,9 @@ async function autoStartMitm() {
|
|||||||
// Need an active API key
|
// Need an active API key
|
||||||
const keys = await getApiKeys();
|
const keys = await getApiKeys();
|
||||||
const activeKey = keys.find(k => k.isActive !== false);
|
const activeKey = keys.find(k => k.isActive !== false);
|
||||||
if (!activeKey) {
|
|
||||||
console.log("[InitApp] MITM auto-start skipped: no active API key");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log("[InitApp] MITM was enabled, auto-starting...");
|
console.log("[InitApp] MITM was enabled, auto-starting...");
|
||||||
await startMitm(activeKey.key, password || "");
|
await startMitm(activeKey?.key || "sk_9router", password || "");
|
||||||
console.log("[InitApp] MITM auto-started");
|
console.log("[InitApp] MITM auto-started");
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.log("[InitApp] MITM auto-start failed:", err.message);
|
console.log("[InitApp] MITM auto-start failed:", err.message);
|
||||||
|
|||||||
Reference in New Issue
Block a user