Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Add a new utility for constructing the host URL for the app. #419

Merged
merged 4 commits into from
Jul 14, 2022

Conversation

byrichardpowell
Copy link
Contributor

@byrichardpowell byrichardpowell commented Jul 12, 2022

WHY are these changes introduced?

For performance soon we will be recommending that apps favor server redirects within the OAuth process. This will replace client side redirects using AppBridge. We want to control that code that constructs the URL for the app. That way it's easier for developers, and if that URL changes we can update the logic with a version bump.

WHAT is this pull request doing?

Add a new utility called getHostAppUrl. This utility constructs the host URL for an app.

This utility will be used to get the URL to redirect to when the store does not have a token for the app.

Type of change

  • Patch: Bug (non-breaking change which fixes an issue)
  • Minor: New feature (non-breaking change which adds functionality)
  • Major: Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

  • I have added a changelog entry, prefixed by the type of change noted above
  • I have added/updated tests for this change
  • I have documented new APIs/updated the documentation for modified APIs (for public APIs)

@byrichardpowell
Copy link
Contributor Author

@paulomarg @vividviolet this is now ready for review. I'm going to test the code manually in the app template.

src/utils/__tests__/get-host-app-url.test.ts Outdated Show resolved Hide resolved
src/utils/__tests__/get-host-app-url.test.ts Outdated Show resolved Hide resolved
src/utils/__tests__/get-host-app-url.test.ts Outdated Show resolved Hide resolved
src/utils/get-host-app-url.ts Outdated Show resolved Hide resolved
Copy link
Member

@henrytao-me henrytao-me left a comment

Choose a reason for hiding this comment

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

LGTM

src/utils/get-host-app-url.ts Outdated Show resolved Hide resolved
Copy link
Member

@vividviolet vividviolet left a comment

Choose a reason for hiding this comment

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

Code looks good to me. I wonder if the util should be called getEmbeddedAppUrl or something? It's not useful for non-embedded apps as the url would not work.

src/utils/__tests__/get-host-app-url.test.ts Outdated Show resolved Hide resolved
src/utils/__tests__/get-host-app-url.test.ts Outdated Show resolved Hide resolved
src/utils/__tests__/get-host-app-url.test.ts Outdated Show resolved Hide resolved
);
}

if (!request.url) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this actually possible?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, this really surprised me, but according to the type definitions it can be undefined:

Screen Shot 2022-07-12 at 5 05 31 PM

Unless I've mis-understood something?

Copy link
Member

Choose a reason for hiding this comment

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

I thought url was always a string according to this https://nodejs.org/api/http.html#messageurl

@byrichardpowell
Copy link
Contributor Author

byrichardpowell commented Jul 12, 2022

I wonder if the util should be called getEmbeddedAppUrl or something? It's not useful for non-embedded apps as the url would not work

@vividviolet Agreed. getEmbeddedAppUrl is much nicer, updated 👍

Copy link
Contributor

@paulomarg paulomarg left a comment

Choose a reason for hiding this comment

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

Nits aside, I think this works!

@byrichardpowell byrichardpowell force-pushed the add-util-for-app-url branch 3 times, most recently from 05ea6a2 to ab55983 Compare July 13, 2022 19:04
Copy link
Member

@henrytao-me henrytao-me left a comment

Choose a reason for hiding this comment

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

LGTM 👍

Copy link
Member

@vividviolet vividviolet left a comment

Choose a reason for hiding this comment

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

This looks good to me

1. Correct typo
2. Change utility name "getHostAppUrl" to "getEmbeddedAppUrl", which is much nicer.
3. Add / to the host in our test.  This matches the format of the host that Shopify provides
4. Flesh out the docs a little more.
5. Use new URL, rather than url.parse. url.parse is deprecated.
@byrichardpowell byrichardpowell merged commit d599ddd into main Jul 14, 2022
@byrichardpowell byrichardpowell deleted the add-util-for-app-url branch July 14, 2022 16:11
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants