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

[REF-843] Automatically update api_url and deploy_url #1954

Merged
merged 2 commits into from
Oct 13, 2023

Conversation

masenf
Copy link
Collaborator

@masenf masenf commented Oct 12, 2023

When backend_port or frontend_port are provided, reformat the defaults for api_url and deploy_url to match.

If either api_url or deploy_url are provided, then they are not implicitly updated (respect the user decision)

Fix REF-843


After this change, just setting reflex run --backend-port will just work without additional configuration. Also, testing apps on other devices is easier, because the API_URL does not need to be set.

When backend_port or frontend_port are provided, reformat the defaults for
api_url and deploy_url to match.

If either api_url or deploy_url are provided, then they are not implicitly
updated (respect the user decision)

Fix REF-843
Copy link
Contributor

@picklelo picklelo left a comment

Choose a reason for hiding this comment

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

This is great, tested and works well for me. Not sure if we need to set the deploy_url though, as it doesn't make sense for it to be localhost

* Get the URL for the websocket connection
* @returns The websocket URL object.
*/
export const getEventURL = () => {
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we're modifying it here, the api_url printed in the debug logs will show the wrong one still. Is it possible to modify the api_url on the Python side instead? Or maybe not since this case handles it wherever they end up deploying it.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The api_url in the logs will show whatever it is set to, there's no real way to munge that correctly on the python side.

I suppose a possible alternative would be to leave "localhost" alone and instead make the magic 0.0.0.0 mean "wherever i end up"?

"deploy_url" not in self._non_default_attributes
and "frontend_port" in kwargs
):
self.deploy_url = f"http://localhost:{kwargs['frontend_port']}"
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think the deploy_url should ever be localhost. We only use this currently for the NextJS sitemap for indexing websites

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The default deploy_url is already "localhost" in the Config... what should it be?

Copy link
Contributor

Choose a reason for hiding this comment

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

I guess localhost is accurate in dev mode, it's just currently only used for the sitemap so it's a bit meaningless.

@picklelo picklelo merged commit 684912e into main Oct 13, 2023
36 checks passed
@masenf masenf mentioned this pull request Oct 16, 2023
@masenf masenf deleted the masenf/dynamic-api-url branch October 18, 2023 18:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants