-
Notifications
You must be signed in to change notification settings - Fork 3
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: localhost subdomain redirection #136
Changes from 10 commits
7079bb6
fb97433
be1cb61
e4bcb6b
2a73ffc
24e678f
e67c0aa
554c9ff
0ed7ad5
4ab717b
402a78d
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,4 +1,4 @@ | ||||||
import { subdomainToBzzResource } from '../../utils/bzz-link' | ||||||
import { createSubdomainUrl, isLocalhost, isSubdomainUsed, subdomainToBzzResource } from '../../utils/bzz-link' | ||||||
import { fakeUrl } from '../../utils/fake-url' | ||||||
import { getItem, StoreObserver } from '../../utils/storage' | ||||||
import { SWARM_SESSION_ID_KEY, unpackSwarmSessionIdFromUrl } from '../../utils/swarm-session-id' | ||||||
|
@@ -58,7 +58,7 @@ export class BeeApiListener { | |||||
): void | chrome.webRequest.BlockingResponse => { | ||||||
console.log('web2OriginEnabled', this._web2OriginEnabled) | ||||||
|
||||||
if (this._web2OriginEnabled) return { responseHeaders: details.responseHeaders } | ||||||
if (this._web2OriginEnabled || isSubdomainUsed(details.url)) return { responseHeaders: details.responseHeaders } | ||||||
|
||||||
const urlArray = details.url.toString().split('/') | ||||||
|
||||||
|
@@ -149,7 +149,7 @@ export class BeeApiListener { | |||||
const bzzReference = subdomainToBzzResource(subdomain) + pathWithParams | ||||||
console.log('bzz link redirect', bzzReference, url, pathWithParams) | ||||||
|
||||||
this.redirectToBzzReference(bzzReference, tabId) | ||||||
this.redirectToBzzReference(bzzReference, tabId, true) | ||||||
}, | ||||||
{ url: [{ hostSuffix: '.bzz.link' }] }, | ||||||
) | ||||||
|
@@ -159,8 +159,8 @@ export class BeeApiListener { | |||||
chrome.webRequest.onBeforeRequest.addListener( | ||||||
(details: chrome.webRequest.WebRequestBodyDetails) => { | ||||||
console.log('Original BZZ Url', details.url) | ||||||
const urlParams = new URLSearchParams(details.url) | ||||||
const query = urlParams.get('oq') | ||||||
const urlParams = new URLSearchParams(new URL(details.url).search) | ||||||
const query = decodeURI(urlParams.get('oq') || urlParams.get('q') || '') | ||||||
|
||||||
if (!query || !query.startsWith('bzz://')) return | ||||||
|
||||||
|
@@ -276,8 +276,25 @@ export class BeeApiListener { | |||||
* @param bzzReference in form of $ROOT_HASH<$PATH><$QUERY> | ||||||
* @param tabId the tab will be navigated to the dApp page | ||||||
*/ | ||||||
private redirectToBzzReference(bzzReference: string, tabId: number) { | ||||||
const url = `${this._beeApiUrl}/bzz/${bzzReference}` | ||||||
private redirectToBzzReference(bzzReference: string, tabId: number, preventSubdomainRedirection = false) { | ||||||
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. remove `preventSubdomainRedirection
Suggested change
|
||||||
let url: string | ||||||
|
||||||
if (preventSubdomainRedirection || !isLocalhost(this._beeApiUrl)) { | ||||||
url = `${this._beeApiUrl}/bzz/${bzzReference}` | ||||||
} else { | ||||||
const [hash, path] = bzzReference.split(/\/(.*)/s) | ||||||
let subdomain = hash | ||||||
|
||||||
if (subdomain.endsWith('.eth')) { | ||||||
subdomain = subdomain.substring(0, subdomain.length - 4) | ||||||
} | ||||||
|
||||||
url = createSubdomainUrl(this._beeApiUrl, subdomain) | ||||||
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. here the subdomain is a swarm hash, but u don't transform it into a CID that the swarm.localhost subdomain requires. |
||||||
|
||||||
if (path) { | ||||||
url += `/${path}` | ||||||
} | ||||||
} | ||||||
|
||||||
console.log(`Fake URL redirection to ${url} on tabId ${tabId}`) | ||||||
|
||||||
|
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.
why do you do that?
cid.bzz.link
also should be mapped to{cid}.swarm.localhost