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

feat: allow support for a root path #5904

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Conversation

jordanrfrazier
Copy link
Collaborator

@jordanrfrazier jordanrfrazier commented Jan 23, 2025

Adds support for adding a root_path, so users can execute on a relative path.

@jordanrfrazier jordanrfrazier requested review from anovazzi1, lucaseduoli and ogabrielluiz and removed request for anovazzi1 January 23, 2025 23:28
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jan 23, 2025
Copy link
Contributor

@ogabrielluiz ogabrielluiz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Jordan! Tejas will appreciate this work for sure.

src/backend/base/langflow/main.py Outdated Show resolved Hide resolved
@@ -44,6 +44,7 @@ const DeleteAccountPage = lazy(() => import("./pages/DeleteAccountPage"));
// const PlaygroundPage = lazy(() => import("./pages/Playground"));

const SignUp = lazy(() => import("./pages/SignUpPage"));
const rootPath = process.env.LANGFLOW_ROOT_PATH || "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is fixed at build time. We have an endpoint that sends config from the backend to the UI at runtime (api/v1/config).

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mind explaining this a bit more? I was following the pattern I saw in the vite config - https://github.com/langflow-ai/langflow/blob/support-base-path/src/frontend/vite.config.mts#L43.

Do you mean that we should rather access the value from the backend config? If so, wouldn't that require the BE be up before a FE can come up?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that if we always set the env on the backend and pass it through a config endpoint is better than using decentralized env variables.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Backend serves the Frontend. Also, that variable won't be available at runtime. When the frontend is built it will grab that and fix the value to whatever it was at the build time.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ogabrielluiz I talked to @anovazzi1 about this and he believes that this is the correct solution. If we want the frontend to be available at a specific root path, does it not need to be available at build time?

@anovazzi1 can likely explain it better.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What this doesn't do is allow a separate root path for the frontend and the backend, but I think that's okay for now

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using useGetConfig to get this puts this PR in a good state. I'd advise adding a Docker compose example on how to use/test this.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Basically putting this on getConfig is not really useful, because this change needs to be done before the frontend builds, that way makes sense reading directly from the env instead of making a request

@ogabrielluiz
Copy link
Contributor

Adds support for adding a root_path, so users can execute on a relative path.

TODO

  • Noticed that curls without the root path still work. Unsure why
    e.g.
curl -s http://localhost:7860/custompath/api/v1/all
and 
curl -s http://localhost:7860/api/v1/all

are both served.

Could be related to this: https://fastapi.tiangolo.com/advanced/behind-a-proxy/#about-root_path

Did you use uvicorn (i.e. make backend) or langflow run?

@jordanrfrazier
Copy link
Collaborator Author

jordanrfrazier commented Jan 24, 2025

Adds support for adding a root_path, so users can execute on a relative path.
TODO

  • Noticed that curls without the root path still work. Unsure why
    e.g.
curl -s http://localhost:7860/custompath/api/v1/all
and 
curl -s http://localhost:7860/api/v1/all

are both served.

Could be related to this: https://fastapi.tiangolo.com/advanced/behind-a-proxy/#about-root_path

Did you use uvicorn (i.e. make backend) or langflow run?

Ah, yes, that must be what this is. That seems like intended behavior - do you see any issue in this then? (And I was running with make backend / make frontend)

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jan 24, 2025
@jordanrfrazier jordanrfrazier marked this pull request as ready for review January 24, 2025 06:10
@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Jan 24, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jan 24, 2025
Copy link
Contributor

@anovazzi1 anovazzi1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe the root_path variable should be retrieved on the config endpoint:
image

@ogabrielluiz
Copy link
Contributor

Adds support for adding a root_path, so users can execute on a relative path.
TODO

  • Noticed that curls without the root path still work. Unsure why
    e.g.
curl -s http://localhost:7860/custompath/api/v1/all
and 
curl -s http://localhost:7860/api/v1/all

are both served.

Could be related to this: fastapi.tiangolo.com/advanced/behind-a-proxy#about-root_path
Did you use uvicorn (i.e. make backend) or langflow run?

Ah, yes, that must be what this is. That seems like intended behavior - do you see any issue in this then? (And I was running with make backend / make frontend)

langflow run uses Gunicorn instead of Uvicorn. Maybe that can have a different behaviour.

@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jan 30, 2025
@github-actions github-actions bot added enhancement New feature or request and removed enhancement New feature or request labels Jan 30, 2025
@@ -44,6 +44,7 @@ const DeleteAccountPage = lazy(() => import("./pages/DeleteAccountPage"));
// const PlaygroundPage = lazy(() => import("./pages/Playground"));

const SignUp = lazy(() => import("./pages/SignUpPage"));
const rootPath = process.env.LANGFLOW_ROOT_PATH || "";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think using useGetConfig to get this puts this PR in a good state. I'd advise adding a Docker compose example on how to use/test this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants