Skip to content

Commit 8c8093e

Browse files
authored
Merge pull request #384 from wasp-lang/filip-tighthen-up-cors
Tighten up S3 CORS configuration
2 parents 889fa09 + 3ce5ff2 commit 8c8093e

File tree

4 files changed

+42
-28
lines changed

4 files changed

+42
-28
lines changed
Loading
Loading

opensaas-sh/blog/src/content/docs/guides/deploying.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ These are the steps necessary for you to deploy your app. We recommend you follo
3030
Each of these steps is covered in more detail below.
3131

3232
### Prerequisites
33-
34-
Make sure you've got all your API keys and environment variables set up before you deploy.
33+
#### AWS S3 CORS configuration
34+
If you're storing files in AWS S3, ensure you've listed your production domain
35+
in the bucket's CORS configuration under `AllowedOrigins`. Check the [File
36+
uploading guide](/guides/file-uploading/#change-the-cors-settings) for details.
3537

3638
#### Env Vars
39+
Make sure you've got all your API keys and environment variables set up before you deploy.
3740
##### Payment Processor Vars
3841
In the [Payments Processor integration guide](/guides/payments-integration/), you set up your API keys using test keys and test product ids. You'll need to get the live/production versions of those keys. To get these, repeat the instructions in the [Integration Guide](/guides/payments-integration/) without being in test mode. Add the new keys to your deployed environment secrets.
3942

opensaas-sh/blog/src/content/docs/guides/file-uploading.mdx

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import defaultSettings from '@assets/file-uploads/default-settings.png';
1111
import newBucket from '@assets/file-uploads/new-bucket.png';
1212
import permissions from '@assets/file-uploads/permissions.png';
1313
import cors from '@assets/file-uploads/cors.png';
14+
import corsExample from '@assets/file-uploads/cors-example.png';
1415
import username from '@assets/file-uploads/username.png';
1516
import keys from '@assets/file-uploads/keys.png';
1617

@@ -61,52 +62,62 @@ To do so, follow the steps in this external guide: [Creating IAM users and S3 bu
6162
Once you are logged in with your IAM user, you'll need to create an S3 bucket to store your files.
6263

6364
1. Navigate to the S3 service in the AWS console
64-
<Image src={findS3} alt="find s3" loading="lazy" />
65+
<Image src={findS3} alt="find s3" loading="lazy" />
6566
2. Click on the `Create bucket` button
66-
<Image src={createBucket} alt="create bucket" loading="lazy" />
67+
<Image src={createBucket} alt="create bucket" loading="lazy" />
6768
3. Fill in the bucket name and region
6869
4. **Leave all the settings as default** and click `Create bucket`
69-
<Image src={defaultSettings} alt="bucket settings" loading="lazy" />
70+
<Image src={defaultSettings} alt="bucket settings" loading="lazy" />
7071

7172
### Change the CORS settings
7273

7374
Now we need to change some permissions on the bucket to allow for file uploads from your app.
7475

7576
1. Click on the bucket you just created
76-
<Image src={newBucket} alt="new bucket" loading="lazy" />
77+
<Image src={newBucket} alt="new bucket" loading="lazy" />
7778
2. Click on the `Permissions` tab
78-
<Image src={permissions} alt="permissions" loading="lazy" />
79+
<Image src={permissions} alt="permissions" loading="lazy" />
7980
3. Scroll down to the `Cross-origin resource sharing (CORS)` section and click `Edit`
80-
<Image src={cors} alt="cors" loading="lazy" />
81-
5. Paste the following CORS configuration and click `Save changes`:
82-
```json
83-
[
84-
{
85-
"AllowedHeaders": [
86-
"*"
87-
],
88-
"AllowedMethods": [
89-
"PUT",
90-
"GET"
91-
],
92-
"AllowedOrigins": [
93-
"*"
94-
],
95-
"ExposeHeaders": []
96-
}
97-
]
98-
```
81+
<Image src={cors} alt="cors" loading="lazy" />
82+
5. Insert the correct CORS configuration and click `Save changes`. You can
83+
copy-paste most of the config below, but **you must edit the
84+
`AllowedOrigins` field** to fit your app. Include `http://localhost:3000` for
85+
local development, and `https://<your domain>` for production.
86+
87+
If you don't yet have a domain name, just list `http://localhost:3000` for
88+
now. We'll remind you to add your domain before deploying to production in
89+
the [Deployment docs](/guides/deploying/#aws-s3-cors-configuration).
90+
```json {11,12}
91+
[
92+
{
93+
"AllowedHeaders": [
94+
"*"
95+
],
96+
"AllowedMethods": [
97+
"PUT",
98+
"GET"
99+
],
100+
"AllowedOrigins": [
101+
"http://localhost:3000",
102+
"https://<your-domain>"
103+
],
104+
"ExposeHeaders": []
105+
}
106+
]
107+
```
108+
As an example, here are the CORS permissions for this site - https://opensaas.sh:
109+
<Image src={corsExample} alt="cors-example" loading="lazy" />
99110

100111
### Get your AWS S3 credentials
101112

102113
Now that you have your S3 bucket set up, you'll need to get your S3 credentials to use in your app.
103114

104115
1. Click on your username in the top right corner of the AWS console and select `Security Credentials`
105-
<Image src={username} alt="username" loading="lazy" />
116+
<Image src={username} alt="username" loading="lazy" />
106117
2. Scroll down to the `Access keys` section
107118
3. Click on `Create Access Key`
108119
4. Select the `Application running on an AWS service` option and create the access key
109-
<Image src={keys} alt="keys" loading="lazy" />
120+
<Image src={keys} alt="keys" loading="lazy" />
110121
5. Copy the `Access key ID` and `Secret access key` and paste them in your `src/app/.env.server` file:
111122
```sh
112123
AWS_S3_IAM_ACCESS_KEY=ACK...

0 commit comments

Comments
 (0)