Spaces:
Running
Running
debug-logs: tail last N lines + masked X credential diagnostics
Browse files- health-server.js +58 -7
health-server.js
CHANGED
|
@@ -1786,18 +1786,69 @@ const server = http.createServer((req, res) => {
|
|
| 1786 |
// ββ /app/debug-logs β Temporary endpoint for debugging βββββββββββββββββββ
|
| 1787 |
if (pathname === "/app/debug-logs") {
|
| 1788 |
try {
|
| 1789 |
-
|
| 1790 |
-
|
| 1791 |
-
|
| 1792 |
-
|
| 1793 |
-
|
| 1794 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1795 |
|
| 1796 |
const cfProxyLog = fs.existsSync("/tmp/huggingpost-cloudflare-proxy.env")
|
| 1797 |
? fs.readFileSync("/tmp/huggingpost-cloudflare-proxy.env", "utf8")
|
| 1798 |
: "No proxy env";
|
| 1799 |
|
| 1800 |
-
const out =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1801 |
res.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" });
|
| 1802 |
res.end(out);
|
| 1803 |
} catch (e) {
|
|
|
|
| 1786 |
// ββ /app/debug-logs β Temporary endpoint for debugging βββββββββββββββββββ
|
| 1787 |
if (pathname === "/app/debug-logs") {
|
| 1788 |
try {
|
| 1789 |
+
// tail helper β last N lines of a file
|
| 1790 |
+
const tailLines = (path, n) => {
|
| 1791 |
+
if (!fs.existsSync(path)) return `(no file: ${path})`;
|
| 1792 |
+
const lines = fs.readFileSync(path, "utf8").split("\n");
|
| 1793 |
+
return lines.slice(-n).join("\n");
|
| 1794 |
+
};
|
| 1795 |
+
|
| 1796 |
+
const errLog = tailLines("/root/.pm2/logs/backend-error.log", 150);
|
| 1797 |
+
const outLog = tailLines("/root/.pm2/logs/backend-out.log", 80);
|
| 1798 |
+
|
| 1799 |
+
// masked credential diagnostics β first 6 chars + length
|
| 1800 |
+
const maskCred = (val) => {
|
| 1801 |
+
if (!val) return "(not set)";
|
| 1802 |
+
const clean = val.trim();
|
| 1803 |
+
if (clean.length === 0) return "(empty)";
|
| 1804 |
+
return `${clean.slice(0, 6)}... (len=${clean.length})`;
|
| 1805 |
+
};
|
| 1806 |
+
const xKey = maskCred(process.env.X_API_KEY);
|
| 1807 |
+
const xSecret = maskCred(process.env.X_API_SECRET);
|
| 1808 |
+
const frontendUrl = process.env.FRONTEND_URL || "(not set)";
|
| 1809 |
+
|
| 1810 |
+
// Heuristic: X Consumer Key is ~25 alphanum, Consumer Secret ~50 alphanum.
|
| 1811 |
+
// OAuth 2.0 Client ID is base64url and usually longer (36+).
|
| 1812 |
+
const xKeyNote = (() => {
|
| 1813 |
+
const v = (process.env.X_API_KEY || "").trim();
|
| 1814 |
+
if (!v) return "MISSING";
|
| 1815 |
+
if (v.length > 35) return "β LOOKS LIKE OAuth2 CLIENT ID (too long) β should be ~25 chars";
|
| 1816 |
+
if (v.includes("=") || v.includes(":")) return "β LOOKS WRONG (contains = or :)";
|
| 1817 |
+
return "β length ok";
|
| 1818 |
+
})();
|
| 1819 |
+
const xSecretNote = (() => {
|
| 1820 |
+
const v = (process.env.X_API_SECRET || "").trim();
|
| 1821 |
+
if (!v) return "MISSING";
|
| 1822 |
+
if (v.length < 40) return "β TOO SHORT β Consumer Secret is ~50 chars";
|
| 1823 |
+
if (v.length > 70) return "β TOO LONG β might be OAuth2 Client Secret or Access Token Secret";
|
| 1824 |
+
if (v.includes("=")) return "β CONTAINS = β might be base64 encoded (wrong key type)";
|
| 1825 |
+
return "β length ok";
|
| 1826 |
+
})();
|
| 1827 |
+
|
| 1828 |
+
const credSection = [
|
| 1829 |
+
"=== X CREDENTIAL CHECK ===",
|
| 1830 |
+
`X_API_KEY : ${xKey} [${xKeyNote}]`,
|
| 1831 |
+
`X_API_SECRET : ${xSecret} [${xSecretNote}]`,
|
| 1832 |
+
`FRONTEND_URL : ${frontendUrl}`,
|
| 1833 |
+
`Expected callback URL: ${frontendUrl}/integrations/social/x`,
|
| 1834 |
+
].join("\n");
|
| 1835 |
|
| 1836 |
const cfProxyLog = fs.existsSync("/tmp/huggingpost-cloudflare-proxy.env")
|
| 1837 |
? fs.readFileSync("/tmp/huggingpost-cloudflare-proxy.env", "utf8")
|
| 1838 |
: "No proxy env";
|
| 1839 |
|
| 1840 |
+
const out = [
|
| 1841 |
+
credSection,
|
| 1842 |
+
"",
|
| 1843 |
+
"=== BACKEND ERROR LOG (last 150 lines) ===",
|
| 1844 |
+
errLog,
|
| 1845 |
+
"",
|
| 1846 |
+
"=== BACKEND OUT LOG (last 80 lines) ===",
|
| 1847 |
+
outLog,
|
| 1848 |
+
"",
|
| 1849 |
+
"=== PROXY ENV ===",
|
| 1850 |
+
cfProxyLog,
|
| 1851 |
+
].join("\n");
|
| 1852 |
res.writeHead(200, { "Content-Type": "text/plain; charset=utf-8" });
|
| 1853 |
res.end(out);
|
| 1854 |
} catch (e) {
|