cli icon indicating copy to clipboard operation
cli copied to clipboard

[Feature]: `app dev` should update URLs and respect paths

Open zirkelc opened this issue 1 year ago • 8 comments

What area(s) will this request affect?

App, Running your code locally

What type of change do you want to see?

New feature

Overview

When shopify app dev runs, it creates a tunnel via Cloudfare and updates the app URLs in Partners Dashboard.

The URLs have the following format:

application_url = "https://trash-shopping-health-inspection.trycloudflare.com"

[auth]
redirect_urls = [
  "https://trash-shopping-health-inspection.trycloudflare.com/auth/callback",
  "https://trash-shopping-health-inspection.trycloudflare.com/auth/shopify/callback",
  "https://trash-shopping-health-inspection.trycloudflare.com/api/auth/callback"
]

where the subdomain trash-shopping-health-inspection is a random string that changes on every app dev.

I would like to suggest to make it possible to configure the paths of each URL. For example, instead of /auth/callback it should be possible to use /app/auth/callback or any other paths. Right now it's always / for the application_url and /auth/callback, /auth/shopify/callback and /api/auth/callback for redirect_urls.

It would be nice if there were two CLI options like --app-url-path=/apps or --redirect-url-path=/app/auth/callback to override the default values. Another option would be, if the CLI updates only the hostname trash-shopping-health-inspection.trycloudflare.com of each URL and doesn't update the paths.

Motivation

I have to work with multiple apps (custom and public apps) on the same backend. In order to re-use the same infrastructure, I have to distinguish the different apps by their ID. I do that by simply adding /apps/<app-id> as prefix to all app URLs.

  1. https://trash-shopping-health-inspection.trycloudflare.com/apps/123/
  2. https://trash-shopping-health-inspection.trycloudflare.com/apps/456/

These two URLs would go through the same Remix backend and the right config is loaded depending on the <app-id>.

The static URL paths from the CLI make it very hard to make app dev work.

zirkelc avatar Jul 17 '24 08:07 zirkelc

Right after opening this issue, I've search through the code to see if I could easily add this feature myself. Of course, I stumbled upon this code:

https://github.com/Shopify/cli/blob/54b1a9b3921b8f673fce0f088e1cd97e7d091932/packages/app/src/cli/services/dev/urls.ts#L145-L165

which seems to refer to the auth_callback_path of the shopify.web.toml. It looks like what I need is already available for redirect_urls .

Is is possible to get the same for application_url, like a new field app_path in shopify.web.toml that will get added to the generated tunnel URL?

By the way, I would be willing to submit a PR for this feature :-)

zirkelc avatar Jul 17 '24 08:07 zirkelc

Hi! Thanks for the suggestion, I think it makes sense. @nickwesselman what do you think?

gonzaloriestra avatar Jul 24 '24 10:07 gonzaloriestra

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

P.S. You can learn more about why we stale issues here.

github-actions[bot] avatar Sep 05 '24 03:09 github-actions[bot]

@nickwesselman sorry to ping you. Do you think this feature would be possible?

zirkelc avatar Sep 05 '24 16:09 zirkelc

Hi @zirkelc -- Sorry for the delayed reply. I dug into the logic here a bit and confirmed that this is actually already possible in the shopify.web.toml with the auth_callback_path option. For example, if I add the last line here to my shopify.web.toml:

name = "remix"
roles = ["frontend", "backend"]
webhooks_path = "/webhooks"
auth_callback_path = ["/hello/world","/foo/bar"]

Then when I run shopify app dev the URLs are updated to:

[auth]
redirect_urls = [
  "https://social-consortium-monroe-cleaner.trycloudflare.com/hello/world",
  "https://social-consortium-monroe-cleaner.trycloudflare.com/foo/bar"
]

Does this solve your need?

nickwesselman avatar Sep 24 '24 13:09 nickwesselman

Hi @zirkelc -- Sorry for the delayed reply. I dug into the logic here a bit and confirmed that this is actually already possible in the shopify.web.toml with the auth_callback_path option. For example, if I add the last line here to my shopify.web.toml:

name = "remix"
roles = ["frontend", "backend"]
webhooks_path = "/webhooks"
auth_callback_path = ["/hello/world","/foo/bar"]

Then when I run shopify app dev the URLs are updated to:

[auth]
redirect_urls = [
  "https://social-consortium-monroe-cleaner.trycloudflare.com/hello/world",
  "https://social-consortium-monroe-cleaner.trycloudflare.com/foo/bar"
]

Does this solve your need?

Yes, but I would like the same behavior for application_url. See this comment https://github.com/Shopify/cli/issues/4219#issuecomment-2232766745

name = "remix"
roles = ["frontend", "backend"]
webhooks_path = "/webhooks"
auth_callback_path = ["/hello/world","/foo/bar"]

# New
app_path = "/foo"

Then shopify app dev should update the application URL:

application_url = "https://trash-shopping-health-inspection.trycloudflare.com/foo"

zirkelc avatar Sep 24 '24 13:09 zirkelc

Sorry sorry, failure to read. Let me confirm with the team that this would not be in conflict with any other plans around the app URL in our roadmap.

nickwesselman avatar Sep 24 '24 20:09 nickwesselman

Hi @zirkelc -- We are open to the feature but before accepting a PR for this, the team raised a couple additional questions we'd need to answer --

  1. Apps can have multiple web.toml, how would we resolve which to use? This isn't an issue for auth_callback_path since they can just be concatenated.
  2. Does this affect the UI extension preview server at all? This probably requires testing -- does appending to the app path affect the expected URL for the HMR websocket connection?
  • Thinking about this more, probably not -- you could use a path in your App URL without this configuration. But it would be good to confirm.

nickwesselman avatar Sep 26 '24 18:09 nickwesselman

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

P.S. You can learn more about why we stale issues here.

github-actions[bot] avatar Nov 08 '24 03:11 github-actions[bot]

Hi @nickwesselman

  1. Apps can have multiple web.toml, how would we resolve which to use? This isn't an issue for auth_callback_path since they can just be concatenated.

Is there any naming conventions when using multiple web.toml files? Otherwise can we determine the right web.toml from the roles array? I assume the same question applies to webhooks_path if an app has multiple web.toml files.

  1. Does this affect the UI extension preview server at all? This probably requires testing -- does appending to the app path affect the expected URL for the HMR websocket connection?>
  • Thinking about this more, probably not -- you could use a path in your App URL without this configuration. But it would be good to confirm.

I have no experience with UI extensions, so not really sure what you meant with that. If you can elaborate in more detail, I can verify this.

zirkelc avatar Nov 14 '24 08:11 zirkelc

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

P.S. You can learn more about why we stale issues here.

github-actions[bot] avatar Dec 28 '24 03:12 github-actions[bot]

not stale

zirkelc avatar Dec 28 '24 07:12 zirkelc

This issue seems inactive. If it's still relevant, please add a comment saying so. Otherwise, take no action. → If there's no activity within a week, then a bot will automatically close this. Thanks for helping to improve Shopify's dev tooling and experience.

P.S. You can learn more about why we stale issues here.

github-actions[bot] avatar Feb 10 '25 03:02 github-actions[bot]