question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[QUESTION] How would I add CORS header `Access-Control-Allow-Origin`?

See original GitHub issue

In developing a web frontend for busylight, I would like to allow the development machine (running a self-hosted dev version of the web UI) to make requests to the server where the busylight API is hosted.

Currently, browsers refuse to make those requests, claiming an Access-Control-Allow-Origin header is missing.

Where would I add that header in busylight_api.py? I don’t think adding the header to every single GET endpoint is the right way – is there some general/middleware layer in which I can add headers to all responses?

I’m willing to make the change and submit a PR – just not too familiar with where in the API code to add things 😅

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:18 (18 by maintainers)

github_iconTop GitHub Comments

2reactions
JnyJnycommented, Aug 13, 2022

I manage dependencies and packaging with the tool poetry. You can pip install it for convenience:

$ python3 -m pip install poetry
$ cd path/to/busylight
$ poetry shell
<venv> $ poetry install --extras webapi
<venv> $ busyserve -D

You can use plain python virtual environments using the requirements.txt in the root of the project, however that file is often out of date:

$ python3 -m venv .venv
$ source .venv/bin/activate
$ python3 -m pip install -r requirements.txt
$ python3 -m pip install -e .
# now busylight is installed in editable mode in the new virtual environment
1reaction
JnyJnycommented, Aug 13, 2022

I’ve updated the top-level README.md to include development installation instructions using poetry. That way its harder for me to forget how it works and mislead people who ask.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How does the 'Access-Control-Allow-Origin' header work?
Access -Control-Allow-Origin is a CORS (cross-origin resource sharing) header. When Site A tries to fetch content from Site B, Site B can send...
Read more >
Cross-Origin Resource Sharing (CORS) - MDN Web Docs
The Cross-Origin Resource Sharing standard works by adding new HTTP headers that let servers describe which origins are permitted to read that ...
Read more >
The Access-Control-Allow-Origin Header Explained
Access -Control-Allow-Origin is a CORS header. CORS, or Cross Origin Resource Sharing, is a mechanism for browsers to let a site running at ......
Read more >
CORS and the Access-Control-Allow-Origin response header
The Access-Control-Allow-Origin header is included in the response from one website to a request originating from another website, and identifies the permitted ...
Read more >
3 Ways to Fix the CORS Error — and How the Access- ...
How does this work? The proxy uses express middleware to apply a Access-Control-Allow-Origin: * header to every response from the server. At its ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found