-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgcloud_cors.js
More file actions
52 lines (43 loc) · 1.35 KB
/
gcloud_cors.js
File metadata and controls
52 lines (43 loc) · 1.35 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
// Imports the Google Cloud client library
const {Storage} = require('@google-cloud/storage');
// Creates a client
const storage = new Storage();
/**
* CORS configuration for GCP bucket
*/
// The ID of your GCS bucket
const bucketName = 'resume_page';
// The origins for this CORS config to allow requests from
const origins = [
'https://localhost:4200',
'https://localhost:4000',
'https://localhost:8000',
'https://michaelglendinning.com',
'wss://michaelglendinning.com',
];
// The response headers to share across origins
const responseHeaders = [
'Content-Type',
'Access-Control-Allow-Origin',
'Access-Control-Allow-Methods',
'Access-Control-Allow-Headers'
];
// The maximum amount of time the browser can make requests before it must
// repeat preflighted requests
const maxAgeSeconds = 3600;
// The HTTP methods to allow
const methods = ["GET", "HEAD", "OPTIONS", "POST"];
async function configureBucketCors() {
await storage.bucket(bucketName).setCorsConfiguration([
{
maxAgeSeconds,
method: methods,
origin: origins,
responseHeader: responseHeaders,
},
]);
console.log(`Bucket ${bucketName} was updated with a CORS config
to allow ${methods.join(', ')} requests from ${origins.join(', ')} sharing
${responseHeaders.join(', ')} responses across origins`);
}
configureBucketCors().catch(console.error);