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(backend): redirect to webpage when querying payment pointer in browser #3298

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

Conversation

cozminu
Copy link
Contributor

@cozminu cozminu commented Feb 13, 2025

Changes proposed in this pull request

  • when a request comes from the browser (containing header Accept with text/html) on the payment pointer url, we redirect to wallet website

Context

fixes #3268

Checklist

  • Related issues linked using fixes #number
  • Tests added/updated
  • Make sure that all checks pass
  • Bruno collection updated (if necessary)
  • Documentation issue created with user-docs label (if necessary)
  • OpenAPI specs updated (if necessary)

@cozminu cozminu self-assigned this Feb 13, 2025
@cozminu cozminu linked an issue Feb 13, 2025 that may be closed by this pull request
@github-actions github-actions bot added pkg: backend Changes in the backend package. type: source Changes business logic labels Feb 13, 2025
Copy link

netlify bot commented Feb 13, 2025

Deploy Preview for brilliant-pasca-3e80ec ready!

Name Link
🔨 Latest commit 4abf0ff
🔍 Latest deploy log https://app.netlify.com/sites/brilliant-pasca-3e80ec/deploys/67c5791ea5b7810008185d46
😎 Deploy Preview https://deploy-preview-3298--brilliant-pasca-3e80ec.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@@ -52,6 +52,16 @@ export async function getWalletAddress(
)
}

// Redirect to the wallet if the client accepts HTML
if (ctx.request.header['accept']?.includes('text/html')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Given that the env should be optional, we should include checking for that in this condition

Copy link
Contributor Author

Choose a reason for hiding this comment

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

got it

if (
deps.config.walletAddressRedirectHtmlPage &&
ctx.request.header['accept']?.includes('text/html')
) {
ctx.set(
'Location',
`${deps.config.walletAddressRedirectHtmlPage}/${ctx.request.header['host']}${ctx.request.url}`
)
ctx.status = 302

@@ -192,6 +192,7 @@ export const Config = {
'MAX_OUTGOING_PAYMENT_RETRY_ATTEMPTS',
5
),
ilpWalletUrl: envString('ILP_WALLET_URL', 'https://interledger.app/me'),
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe something like WALLET_ADDRESS_REDIRECT_HTML_PAGE? Should be optional as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

walletAddressRedirectHtmlPage: process.env.WALLET_ADDRESS_REDIRECT_HTML_PAGE,

) {
ctx.set(
'Location',
`${deps.config.walletAddressRedirectHtmlPage}/${ctx.request.header['host']}${ctx.request.url}`
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 would be good to have as a separate middleware for the wallet address route (and should be the first one registered, since we should redirect as soon as possible, without needing to do other operations)

Copy link
Contributor Author

@cozminu cozminu Feb 18, 2025

Choose a reason for hiding this comment

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

Made a separate middleware redirectIfBrowserAcceptsHtml which I put below getWalletAddressUrlFromPath in order to get the processed wallet address instead of redundantly composing it

router.get(
WALLET_ADDRESS_PATH,
getWalletAddressUrlFromPath,
redirectIfBrowserAcceptsHtml,

) {
ctx.set(
'Location',
`${deps.config.walletAddressRedirectHtmlPage}/${ctx.request.header['host']}${ctx.request.url}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
`${deps.config.walletAddressRedirectHtmlPage}/${ctx.request.header['host']}${ctx.request.url}`
`${deps.config.walletAddressRedirectHtmlPage}/${ctx.params.walletAddressPath}`

Copy link
Contributor Author

@cozminu cozminu Feb 18, 2025

Choose a reason for hiding this comment

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

using walletAddressPath and moved it to the new middleware, but still needed some processing to remove http://

const walletAddressPath = ctx.walletAddressUrl.replace('https://', '')
if (
config.walletAddressRedirectHtmlPage &&
ctx.request.header['accept']?.includes('text/html')
) {
ctx.set(
'Location',
`${config.walletAddressRedirectHtmlPage}/${walletAddressPath}`
)

@github-actions github-actions bot added the type: tests Testing related label Feb 18, 2025
) {
ctx.set(
'Location',
`${config.walletAddressRedirectHtmlPage}/${walletAddressPath}`
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's make sure if the integrator enters a walletAddressRedirectHtmlPage with a trailing slash that we don't add the extra /. Something that would happen for sure 😅

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

const redirectHtmlPage = config.walletAddressRedirectHtmlPage.replace(
/\/+$/,
''
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pkg: backend Changes in the backend package. type: source Changes business logic type: tests Testing related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Redirect to webpage when querying payment pointer in browser
2 participants