-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-minio.js
More file actions
64 lines (55 loc) · 2.2 KB
/
Copy pathtest-minio.js
File metadata and controls
64 lines (55 loc) · 2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
const { Client } = require('minio');
const { config } = require('dotenv');
const path = require('path');
// Load environment variables
config({
path: [
path.join(process.cwd(), '.env'),
path.join(process.cwd(), '../../.env'),
],
override: false,
});
async function testMinIOConnection() {
const minioConfig = {
endpoint: process.env.MINIO_ENDPOINT || 's3.dw3tr.com',
port: parseInt(process.env.MINIO_PORT || '443', 10),
useSSL: process.env.MINIO_USE_SSL !== 'false',
accessKey: process.env.MINIO_ACCESS_KEY || 'dw3tr',
secretKey: process.env.MINIO_SECRET_KEY || 'DevOpsRul3z!@#',
bucketName: process.env.MINIO_BUCKET_NAME || 'uploads',
publicUrl: process.env.MINIO_PUBLIC_URL || 'https://s3.dw3tr.com',
};
console.log('🔧 MinIO Configuration:', {
endpoint: minioConfig.endpoint,
port: minioConfig.port,
useSSL: minioConfig.useSSL,
bucketName: minioConfig.bucketName,
publicUrl: minioConfig.publicUrl,
});
const client = new Client({
endPoint: minioConfig.endpoint,
port: minioConfig.port,
useSSL: minioConfig.useSSL,
accessKey: minioConfig.accessKey,
secretKey: minioConfig.secretKey,
});
try {
console.log('🔄 Testing MinIO connection...');
const buckets = await client.listBuckets();
console.log('✅ MinIO connection successful!');
console.log('📂 Available buckets:', buckets.map(b => b.name));
// Test if target bucket exists
const bucketExists = await client.bucketExists(minioConfig.bucketName);
console.log(`📁 Bucket "${minioConfig.bucketName}" exists:`, bucketExists);
if (!bucketExists) {
console.log(`🔄 Creating bucket "${minioConfig.bucketName}"...`);
await client.makeBucket(minioConfig.bucketName, 'us-east-1');
console.log(`✅ Bucket "${minioConfig.bucketName}" created successfully!`);
}
console.log('🎉 MinIO setup is working correctly!');
} catch (error) {
console.error('❌ MinIO connection failed:', error.message);
console.error('Full error:', error);
}
}
testMinIOConnection();