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

Add CORS headers in preview mode #1583

Closed
lfkpoa opened this issue Aug 15, 2024 · 7 comments · Fixed by #1637
Closed

Add CORS headers in preview mode #1583

lfkpoa opened this issue Aug 15, 2024 · 7 comments · Fixed by #1637
Labels
enhancement New feature or request

Comments

@lfkpoa
Copy link

lfkpoa commented Aug 15, 2024

Hello,

We use Observable with API calls to a few different servers.
The users connect with their own ID to these servers to get the data if they are authorized.
But I can't use Observable Framework preview server while developing because of CORS.
When I create react apps with create-react-app, their preview server (npm start) adds CORS headers automatically and I can test the app:

access-control-allow-headers: *
access-control-allow-methods: *
access-control-allow-origin: *

So, I'm suggesting to add these CORS headers automatically to the preview server as well or, at least, add a config that enables this feature.

Thank you.

@lfkpoa lfkpoa added the enhancement New feature or request label Aug 15, 2024
@codingedgar
Copy link

Would be great to have something like https://vitejs.dev/config/server-options.html#server-proxy

@mbostock
Copy link
Member

mbostock commented Sep 3, 2024

@lfkpoa Interesting! Are you using Framework’s preview server in production rather than just for development preview? I would love to hear more about how your setup so I can better understand this use case. 🙏

@lfkpoa
Copy link
Author

lfkpoa commented Sep 3, 2024

Hi @mbostock

We try to use the preview server while developing and testing only.
We need to connect to our API server to get the data, but we face CORS restriction.
The use of the preview server makes it a lot easier to develop and test new ideias very fast.
We managed to make a local fork of the framework to only add the required cors headers to preview server and it worked.
In production we deploy to a web server configured to allow CORS to our API server.
We connect to the API server to always get fresh data and because the user usually selects to interact with a small portion (related to a few clients) from huge tables.
In the browser we use mostly Arquero but also DuckDB to manipulate the data.
Thank you

@kzmKZuzmo
Copy link

kzmKZuzmo commented Sep 6, 2024

hi the same here I try observable framework and I need to some modification to call some oxternal api and I always get this
Access to XMLHttpRequest at 'https://test.test' from origin 'http://localhost:3001' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

and I use this "dev": "tsx watch --ignore docs --no-warnings=ExperimentalWarning ./src/bin/observable.ts preview --no-open"

to run my observable

@mbostock
Copy link
Member

mbostock commented Sep 6, 2024

@kzmKZuzmo That sounds unrelated to this issue and like you should move your request to the oexternal API into a data loader. Alternatively you need to enable CORS to your test.test server, not to the Framework preview server.

@kzmKZuzmo
Copy link

@mbostock so maybe you can help me What I need is write directly data into duckdb wasm without storing on the server only inside client is that possible ?

@mbostock
Copy link
Member

mbostock commented Sep 6, 2024

@kzmKZuzmo Please open a new discussion if you’d like to ask for help on another topic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants