Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Correct Cors #38

Open
zlafil opened this issue Jan 12, 2022 · 1 comment
Open

Correct Cors #38

zlafil opened this issue Jan 12, 2022 · 1 comment

Comments

@zlafil
Copy link
Contributor

zlafil commented Jan 12, 2022

Using app.use(cors()) will always set the response header access-control-allow-origin to the callingURL.
For example calling the API from https://divid.se will set the responding header: access-control-allow-origin: https://divid.se

This works well when there is no cache in front of the API. When there is a cache the header will be cached. This means that other sites wont be able to reach the same resource. Only the site that first called the resource will be able to get it-

Solution:
changing app.use(cors()) to app.use(cors({ origin: "*" }));
This will ensure the header access-control-allow-origin is set to *

@jonaskello
Copy link
Member

Yes that seems OK with me if someone wants to do a PR for that.

@jonaskello jonaskello removed their assignment Jan 12, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants