Dynamic Intelligence
commited on
Commit
·
00a956c
1
Parent(s):
6e4988e
Fix 401 error: Add authenticated API proxy for private datasets
Browse files
src/app/api/hf-proxy/route.ts
CHANGED
|
@@ -25,16 +25,27 @@ async function handleRequest(request: NextRequest, method: 'GET' | 'HEAD') {
|
|
| 25 |
}
|
| 26 |
|
| 27 |
// Get token from environment variable (set in Hugging Face Space secrets)
|
| 28 |
-
//
|
| 29 |
-
const token =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
// Log token status for debugging (don't log actual token value)
|
| 32 |
if (!token) {
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
} else {
|
| 37 |
-
console.log('✓ HF_TOKEN found
|
| 38 |
}
|
| 39 |
|
| 40 |
try {
|
|
|
|
| 25 |
}
|
| 26 |
|
| 27 |
// Get token from environment variable (set in Hugging Face Space secrets)
|
| 28 |
+
// Try multiple possible variable names that Hugging Face Spaces might use
|
| 29 |
+
const token =
|
| 30 |
+
process.env.HF_TOKEN ||
|
| 31 |
+
process.env.HUGGINGFACE_TOKEN ||
|
| 32 |
+
process.env.HF_API_TOKEN ||
|
| 33 |
+
process.env.HUGGING_FACE_HUB_TOKEN ||
|
| 34 |
+
// Also check if it's available in the request headers (for debugging)
|
| 35 |
+
request.headers.get('x-hf-token') || null;
|
| 36 |
|
| 37 |
// Log token status for debugging (don't log actual token value)
|
| 38 |
if (!token) {
|
| 39 |
+
const envKeys = Object.keys(process.env).filter(k =>
|
| 40 |
+
k.includes('HF') || k.includes('TOKEN') || k.includes('HUGGING')
|
| 41 |
+
);
|
| 42 |
+
console.error('❌ HF_TOKEN not found!');
|
| 43 |
+
console.error('Checked: HF_TOKEN, HUGGINGFACE_TOKEN, HF_API_TOKEN, HUGGING_FACE_HUB_TOKEN');
|
| 44 |
+
console.error('Available env vars with HF/TOKEN:', envKeys.length > 0 ? envKeys.join(', ') : 'NONE');
|
| 45 |
+
console.error('⚠️ Requests to private repos will fail with 401');
|
| 46 |
+
console.error('💡 Make sure HF_TOKEN secret is added in Space Settings → Variables and secrets');
|
| 47 |
} else {
|
| 48 |
+
console.log('✓ HF_TOKEN found (length:', token.length, 'chars, starts with:', token.substring(0, 5) + '...')');
|
| 49 |
}
|
| 50 |
|
| 51 |
try {
|