Skip to content

Commit

Permalink
update docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Chriscbr committed Sep 10, 2024
1 parent f8b61b8 commit bc17f2f
Show file tree
Hide file tree
Showing 3 changed files with 77 additions and 5 deletions.
35 changes: 35 additions & 0 deletions docs/api/04-standard-library/cloud/bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,41 @@ store.onDelete(inflight (key: str) => {
});
```

### Configuring CORS

By default, buckets are configured with CORS for any origin. When a bucket is private (the default), CORS options only come into play when the bucket's objects are accessed through a signed URL.

```js playground example
bring cloud;

let uploads = new cloud.Bucket(
// these are the default options:
public: false,
cors: true,
corsOptions: {
allowedMethods: [http.HttpMethod.GET, http.HttpMethod.POST, http.HttpMethod.PUT, http.HttpMethod.DELETE, http.HttpMethod.HEAD]
allowedOrigins: ["*"],
allowedHeaders: ["*"],
exposeHeaders: [],
maxAge: 0s
},
)
```

The CORS configuration can be disabled by passing `cors: false` to the constructor. CORS rules can also be configured after the bucket is created by calling the `addCorsRule` method:

```js playground example
bring cloud;

let bucket = new cloud.Bucket(
cors: false, // disable any default CORS rules
);

bucket.addCorsRule({
allowedOrigins: ["https://example.com"],
});
```

## Target-specific details

### Simulator (`sim`)
Expand Down
35 changes: 35 additions & 0 deletions packages/@winglang/sdk/src/cloud/bucket.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,41 @@ store.onDelete(inflight (key: str) => {
});
```

### Configuring CORS

By default, buckets are configured with CORS for any origin. When a bucket is private (the default), CORS options only come into play when the bucket's objects are accessed through a signed URL.

```js playground example
bring cloud;

let uploads = new cloud.Bucket(
// these are the default options:
public: false,
cors: true,
corsOptions: {
allowedMethods: [http.HttpMethod.GET, http.HttpMethod.POST, http.HttpMethod.PUT, http.HttpMethod.DELETE, http.HttpMethod.HEAD]
allowedOrigins: ["*"],
allowedHeaders: ["*"],
exposeHeaders: [],
maxAge: 0s
},
)
```

The CORS configuration can be disabled by passing `cors: false` to the constructor. CORS rules can also be configured after the bucket is created by calling the `addCorsRule` method:

```js playground example
bring cloud;

let bucket = new cloud.Bucket(
cors: false, // disable any default CORS rules
);

bucket.addCorsRule({
allowedOrigins: ["https://example.com"],
});
```

## Target-specific details

### Simulator (`sim`)
Expand Down
12 changes: 7 additions & 5 deletions tests/sdk_tests/bucket/cors.test.w
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ bring expect;

let api = new cloud.Api();

let bucket = new cloud.Bucket(public: true, cors: false);

bucket.addCorsRule(
allowedMethods: [http.HttpMethod.GET],
allowedOrigins: [api.url]
let bucket = new cloud.Bucket(
public: false,
cors: true,
corsOptions: {
allowedMethods: [http.HttpMethod.GET],
allowedOrigins: [api.url]
},
);

bucket.addObject("hello", "hello");
Expand Down

0 comments on commit bc17f2f

Please sign in to comment.