added saving photos to firebase
This commit is contained in:
36
scripts/set-cors.mjs
Normal file
36
scripts/set-cors.mjs
Normal file
@@ -0,0 +1,36 @@
|
||||
import { readFileSync } from 'fs';
|
||||
|
||||
const config = JSON.parse(readFileSync(
|
||||
'C:\\Users\\tomas\\.config\\configstore\\firebase-tools.json', 'utf-8'
|
||||
));
|
||||
const token = config.tokens.access_token;
|
||||
|
||||
// Try to list buckets first
|
||||
const listRes = await fetch('https://storage.googleapis.com/storage/v1/b?project=map-jurnal', {
|
||||
headers: { Authorization: `Bearer ${token}` },
|
||||
});
|
||||
const buckets = await listRes.json();
|
||||
console.log('Buckets:', buckets.items?.map(b => b.name) ?? buckets);
|
||||
|
||||
const bucket = 'map-jurnal.appspot.com';
|
||||
const corsConfig = [{
|
||||
origin: ['http://localhost:5173', 'https://map-jurnal.web.app', 'https://map-jurnal.firebaseapp.com'],
|
||||
method: ['GET', 'HEAD', 'PUT', 'POST', 'DELETE'],
|
||||
maxAgeSeconds: 3600,
|
||||
}];
|
||||
|
||||
const res = await fetch(`https://storage.googleapis.com/storage/v1/b/${bucket}`, {
|
||||
method: 'PATCH',
|
||||
headers: {
|
||||
Authorization: `Bearer ${token}`,
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ cors: corsConfig }),
|
||||
});
|
||||
|
||||
if (res.ok) {
|
||||
console.log('CORS configured successfully!');
|
||||
} else {
|
||||
const text = await res.text();
|
||||
console.error('Failed:', res.status, text);
|
||||
}
|
||||
Reference in New Issue
Block a user