-
Notifications
You must be signed in to change notification settings - Fork 24
fetch with cors proxy #604
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,7 @@ | ||
| import { bech32, utf8 } from '@scure/base' | ||
|
|
||
| const corsProxyUrl = 'https://cors-header-proxy.bordalix.workers.dev/proxy?apiurl=' | ||
|
|
||
| const emailRegex = | ||
| /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/ | ||
|
|
||
|
|
@@ -26,6 +28,13 @@ type LnUrlCallbackResponse = { | |
| pr: string | ||
| } | ||
|
|
||
| const fetchWithCorsProxy = (url: string, options?: RequestInit): Promise<Response> => { | ||
| // don't use proxy in tests to avoid CORS issues with Playwright's request interception | ||
| const isPlaywrightTest = typeof process !== 'undefined' && process?.env?.PLAYWRIGHT_TEST === '1' | ||
| const proxyUrl = isPlaywrightTest ? url : `${corsProxyUrl}${encodeURIComponent(url)}` | ||
| return fetch(proxyUrl, options) | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| const checkResponse = <T = any>(response: Response): Promise<T> => { | ||
| if (!response.ok) return Promise.reject(response) | ||
| return response.json() | ||
|
|
@@ -41,7 +50,7 @@ const checkLnUrlResponse = (amount: number, data: LnUrlResponse) => { | |
| const fetchLnUrlInvoice = async (amount: number, note: string, data: LnUrlResponse) => { | ||
| let url = `${data.callback}?amount=${amount}` | ||
| if (note) url += `&comment=${note}` | ||
| const res = await fetch(url).then(checkResponse<LnUrlCallbackResponse>) | ||
| const res = await fetchWithCorsProxy(url).then(checkResponse<LnUrlCallbackResponse>) | ||
|
Comment on lines
52
to
+53
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
🐛 Proposed fix- if (note) url += `&comment=${note}`
+ if (note) url += `&comment=${encodeURIComponent(note)}`🤖 Prompt for AI Agents |
||
| return res.pr | ||
| } | ||
|
|
||
|
|
@@ -78,7 +87,7 @@ export const getCallbackUrl = (lnurl: string): string => { | |
| export const checkLnUrlConditions = (lnurl: string): Promise<LnUrlResponse> => { | ||
| return new Promise<LnUrlResponse>((resolve, reject) => { | ||
| const url = getCallbackUrl(lnurl) | ||
| fetch(url) | ||
| fetchWithCorsProxy(url) | ||
| .then(checkResponse<LnUrlResponse>) | ||
| .then(resolve) | ||
| .catch(reject) | ||
|
|
@@ -89,7 +98,7 @@ export const fetchInvoice = (lnurl: string, sats: number, note: string): Promise | |
| return new Promise<string>((resolve, reject) => { | ||
| const url = getCallbackUrl(lnurl) | ||
| const amount = Math.round(sats * 1000) // millisatoshis | ||
| fetch(url) | ||
| fetchWithCorsProxy(url) | ||
| .then(checkResponse<LnUrlResponse>) | ||
| .then((data) => checkLnUrlResponse(amount, data)) | ||
| .then((data) => fetchLnUrlInvoice(amount, note, data)) | ||
|
|
@@ -101,7 +110,7 @@ export const fetchInvoice = (lnurl: string, sats: number, note: string): Promise | |
| export const fetchArkAddress = (lnurl: string): Promise<ArkMethodResponse> => { | ||
| return new Promise<ArkMethodResponse>((resolve, reject) => { | ||
| const url = getCallbackUrl(lnurl) + '?method=ark' | ||
| fetch(url) | ||
| fetchWithCorsProxy(url) | ||
| .then(checkResponse<ArkMethodResponse>) | ||
| .then(resolve) | ||
| .catch(reject) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hardcoded personal CORS proxy is a critical trust, privacy, and reliability blocker.
All LNURL-related network traffic — including payment callbacks, Lightning invoices, and Ark addresses — is routed through
cors-header-proxy.bordalix.workers.dev, a proxy on an individual developer's personal account. This carries several hard blockers for any merge:Before this can be merged, the solution needs either:
🤖 Prompt for AI Agents