aws / aws/chalice

How to specify multiple origins in a CORSConfig?

Open
#2,122 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
11.1k
Forks
1k
Avg merge
1d 22h
Merged PRs (30d)
2

Description

Apologies if this is an obvious or redundant question, I'm very new to Chalice and backend web in general.

I'm trying to connect my website's frontend to my Chalice REST API. My website has two subdomains: "mywebsite.com" and "www.mywebsite.com". I would like to add both of these origins to my CORSConfig for an API route. The documentation states:

> You should only supply a single origin to the `CORSConfig` object. If you need to supply multiple origins you will need to define a custom handler for it that accepts `OPTIONS` requests and matches the `Origin` header against a whitelist of origins. If the match is successful then return just their `Origin` back to them in the `Access-Control-Allow-Origin` header.

Is there some additional guidance, beyond this doc, on best practices for implementing this? I have no clue what this handler should look like.

Contributor guide

Open the contributing guide

Research direction

Start with the CORSConfig documentation and the custom OPTIONS-handler guidance quoted in the issue. Clarify how the Origin whitelist should be matched and which response header is expected; done means a newcomer can configure both listed origins without guessing.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, python
Domain
api, cloud
Issue type
Documentation
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Needs clarification
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.