LuvKaranwal21 commented on issue #24895:
URL: https://github.com/apache/superset/issues/24895#issuecomment-2796022821

   Hello, yes, I resolved it with reverse proxy, basically my application's 
port ran on `3000` and when I embedded superset (running on 9000) in my app, I 
started getting cross origin errors, so I set up an reverse proxy like this:
   
   ```
   app = FastAPI()
   superset_port = 9000
   
   @app.api_route("/superset/{path:path}", methods=["GET", "POST", "PUT", 
"DELETE", "OPTIONS", "HEAD", "PATCH"])
   async def proxy(request: Request, path: str):
       proxy_url = f"http://localhost:{superset_port}/superset/{path}";
       async with httpx.AsyncClient() as client:
           # Forward the request
           proxy_response = await client.request(
               method=request.method,
               url=proxy_url,
               headers=request.headers.raw,
               content=await request.body()
           )
           # Send the response back to the client
           return Response(
               content=proxy_response.content,
               status_code=proxy_response.status_code,
               headers=dict(proxy_response.headers)
           )
   .
   .
   .
   and so on for all the routes present in superset ...around 12-15 more.
   ```
   
   
   How I serve frontend files ?
   
   ```
   from fastapi.staticfiles import StaticFiles
   class CustomStaticFiles(StaticFiles):
       async def get_response(self, path: str, scope):
           response = await super().get_response(path, scope)
           # Ensure JavaScript files are served with the correct MIME type
           if path.endswith(".js"):
               response.headers["Content-Type"] = "application/javascript"
           return response
   app.mount("/", CustomStaticFiles(directory="../ui/dist", html=True), 
name="my_app")
   ```
   
   
   Now, I serve my app (FastAPI). Both of the above pieces of code resides in 
the same file. Also, make sure to build your frontend first before running the 
app.
   
   Hope this helps, or gives a clue.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to