Accessing flow as API from astra.datastax.com gives CORS error
I created a flow on Astra datastax. it is working fine but when i am trying to use it as api. It giving CORS error. Does it require any special setting there.
Here is the error detail. Access to fetch at 'https://api.langflow.astra.datastax.com/lf/05174a38-787c-439e-ad84-28445ceb70ad/api/v1/run/feaab329-bd0c-4a5e-a1c5-22eb9e87451d?stream=false' from origin 'null' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled
To resolve the CORS error when accessing your Langflow API on Astra Datastax, you need to ensure that the CORS settings in your Langflow deployment are correctly configured. Langflow uses CORSMiddleware from FastAPI to handle CORS settings. By default, it allows requests from any origin, which should prevent CORS errors:
app.add_middleware(
CORSMiddleware,
allow_origins=["*"], # Allows requests from any origin
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
If you are still encountering CORS issues, it might be due to specific configurations or restrictions on Astra Datastax. You can try the following:
-
Check Astra Datastax Settings: Ensure that there are no additional CORS restrictions or settings on Astra Datastax that might be affecting your API.
-
Modify Allowed Origins: If you want to restrict access to specific origins, update the
allow_originslist with the specific domains you want to allow:origins = ["https://your-allowed-origin.com"] app.add_middleware( CORSMiddleware, allow_origins=origins, allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) -
Verify Deployment: Make sure that the CORS settings are correctly applied in your deployment environment.
If the issue persists, it might be helpful to check any logs or debugging tools provided by Astra Datastax to diagnose the problem further.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other
I'm getting the same error, and I want to use the API directly from the frontend. Where can I enable CORS on the Langflow platform? I can't find any CORS settings there.
Error: Access to fetch at 'https://api.langflow.astra.datastax.com/api/lf/cbc8b8a9-8e4e-405b-9999-6a4bf19736c1/api/v1/run/3f814d35-187d-401a-a479-def1559db4a6?stream=false' from origin 'http://localhost:5173/' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.
@dosu Issue is coming when accessing flow as api from live datastax server not local deployment. I dont think i can change any where there.
To enable CORS settings on the Langflow platform when accessing the API, you need to modify the create_app function in the src/backend/base/langflow/main.py file. The CORS settings are configured using the CORSMiddleware from FastAPI. Here is the relevant code snippet:
def create_app():
"""Create the FastAPI app and include the router."""
configure()
socketio_server = socketio.AsyncServer(async_mode="asgi", cors_allowed_origins="*", logger=True)
lifespan = get_lifespan(socketio_server=socketio_server)
app = FastAPI(lifespan=lifespan)
origins = ["*"]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
app.add_middleware(JavaScriptMIMETypeMiddleware)
# Additional setup code...
In this setup, allow_origins is set to ["*"], which means that requests from any origin are allowed. You can modify the origins list to specify particular origins if needed [1].
If you are unable to change these settings on a live Datastax server, you might need to check if there are any additional configurations or restrictions imposed by the server environment that could be affecting CORS.
To continue talking to Dosu, mention @dosu.
Help Dosu learn! Give it feedback: Great Response | Irrelevant Answer | Incorrect Sources | Too Verbose | Hallucination | Other
That solution doesn't sound useful because if we want to deploy the app we have to use the API and we don't have access to that file there.
I encountered a different issue related to a 502 Bad Gateway error from the AstraDB component when making an API call. However, I believe this might provide a useful hint for your issue as well, and this is still open, so...
The fix involved reviewing the TWEAK settings and comparing them with the actual contents of the flow JSON file. There were discrepancies between these, which caused errors when using the API code.
For instance, in my case, the issue stemmed from the "d_api_endpoint" being set inside the AstraDB component, which conflicted with "api_endpoint", as the former takes precedence. or instead of using d_api_empoint, just use api_endpoint and your appropriate token for DB access.
@Jeo-Jang we are still facing the same issue can you please give me full solution of this problem.
I didn't find a way to fix it. As workaround I'm set up a middleware and makes the calls from the server instead.
@dosu Has any progress been made to allow customization of the CORS settings of edge functions in the Astra Web UI? Thank you!
Would be great to be able to configure CORS from env variables.
We are getting 502 gateway error and unable to get the response while we have already integrated the langflow,even the workflow is not that complicated ,,it take 1 to 2 min just to respond back
Cloud v1 is disabled.
Cloud v2 version 1.6.4 has been released with several bug fixes.