Fix MinIO connection by disabling SSL and add debugging
- Change MinIO configuration to use non-SSL connection (useSSL: false) - Add test-connection endpoint to verify MinIO connectivity - Add comprehensive logging to track connection issues - Enhance error messages in list files API for better debugging
This commit is contained in:
@@ -2,12 +2,17 @@ import { listFiles } from '~/server/utils/minio';
|
||||
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
console.log('List files API called');
|
||||
const query = getQuery(event);
|
||||
const prefix = (query.prefix as string) || '';
|
||||
const recursive = query.recursive === 'true';
|
||||
|
||||
console.log('Listing files with prefix:', prefix, 'recursive:', recursive);
|
||||
|
||||
const files = await listFiles(prefix, recursive);
|
||||
|
||||
console.log('Files retrieved:', files.length);
|
||||
|
||||
// Format file list with additional metadata
|
||||
const formattedFiles = (files as any[]).map(file => ({
|
||||
...file,
|
||||
@@ -30,11 +35,13 @@ export default defineEventHandler(async (event) => {
|
||||
count: formattedFiles.length,
|
||||
currentPath: prefix,
|
||||
};
|
||||
} catch (error) {
|
||||
console.error('Failed to list files:', error);
|
||||
} catch (error: any) {
|
||||
console.error('Failed to list files - Full error:', error);
|
||||
console.error('Error message:', error.message);
|
||||
console.error('Error stack:', error.stack);
|
||||
throw createError({
|
||||
statusCode: 500,
|
||||
statusMessage: 'Failed to list files',
|
||||
statusMessage: error.message || 'Failed to list files',
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
62
server/api/files/test-connection.ts
Normal file
62
server/api/files/test-connection.ts
Normal file
@@ -0,0 +1,62 @@
|
||||
export default defineEventHandler(async (event) => {
|
||||
try {
|
||||
const config = useRuntimeConfig().minio;
|
||||
|
||||
// Log configuration (without secrets)
|
||||
const configInfo = {
|
||||
endPoint: config.endPoint,
|
||||
port: config.port,
|
||||
useSSL: config.useSSL,
|
||||
bucketName: config.bucketName,
|
||||
hasAccessKey: !!config.accessKey,
|
||||
hasSecretKey: !!config.secretKey,
|
||||
accessKeyLength: config.accessKey?.length || 0,
|
||||
secretKeyLength: config.secretKey?.length || 0,
|
||||
};
|
||||
|
||||
console.log('Testing MinIO connection with config:', configInfo);
|
||||
|
||||
// Import MinIO client
|
||||
const { Client } = await import('minio');
|
||||
|
||||
// Create client
|
||||
const client = new Client({
|
||||
endPoint: config.endPoint,
|
||||
port: parseInt(config.port),
|
||||
useSSL: config.useSSL,
|
||||
accessKey: config.accessKey,
|
||||
secretKey: config.secretKey,
|
||||
});
|
||||
|
||||
// Test bucket exists
|
||||
const bucketExists = await client.bucketExists(config.bucketName);
|
||||
console.log(`Bucket ${config.bucketName} exists:`, bucketExists);
|
||||
|
||||
// If bucket doesn't exist, try to create it
|
||||
if (!bucketExists) {
|
||||
console.log(`Attempting to create bucket ${config.bucketName}`);
|
||||
await client.makeBucket(config.bucketName, 'us-east-1');
|
||||
console.log(`Bucket ${config.bucketName} created successfully`);
|
||||
}
|
||||
|
||||
// List buckets to verify connection
|
||||
const buckets = await client.listBuckets();
|
||||
console.log('Available buckets:', buckets.map(b => b.name));
|
||||
|
||||
return {
|
||||
success: true,
|
||||
connection: 'successful',
|
||||
config: configInfo,
|
||||
bucketExists,
|
||||
availableBuckets: buckets.map(b => b.name),
|
||||
};
|
||||
} catch (error: any) {
|
||||
console.error('MinIO connection test failed:', error);
|
||||
return {
|
||||
success: false,
|
||||
error: error.message,
|
||||
stack: error.stack,
|
||||
code: error.code,
|
||||
};
|
||||
}
|
||||
});
|
||||
Reference in New Issue
Block a user