-
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
Conversation
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.
This should work only in case of localhost
as that is the only supported redirection from Bee side.
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.
I just tried it out with my local build but it does not redirect the bzz://{content hash}
to the localhost subdomain...
src/utils/bzz-link.ts
Outdated
@@ -62,6 +66,22 @@ export function subdomainToBzzResource(subdomain: string): string { | |||
return `${subdomain}.eth` | |||
} | |||
|
|||
export function isHostIpAddress(url: string): boolean { |
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.
not used function
src/utils/bzz-link.ts
Outdated
@@ -1,6 +1,10 @@ | |||
/** bzz.link CID implementaion */ | |||
import * as swarmCid from '@ethersphere/swarm-cid' | |||
|
|||
const ipAsHostRegex = RegExp( |
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.
it is not needed anymore.
Now it should work. Could you try again? |
one additional thing that we missed out is updating |
I think the swarm-extension/src/background/listener/bee-api.listener.ts Lines 76 to 91 in 554c9ff
|
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.
it still does not work on my side...
we need to redirect
bzz://{swarm hash or ens}/{path}
andhttps://{cid or ens}.bzz.link/{path}
tohttp://{cid or ens without .eth}.swarm.localhost:{port}/{path}
src/utils/bzz-link.ts
Outdated
export function createSubdomainUrl(beeApiUrl: string, subdomain: string): string { | ||
const [protocol, host] = beeApiUrl.split('://') | ||
|
||
return `${protocol}://${subdomain}.${host}` |
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.
host here should be prefixed with swarm.
now it seems like it creates a CID from a CID of the |
now, the subdomain is mapped to the swarm hash reference instead of the CID. please check out the desired mapping in my previous comment |
@@ -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) |
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
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 comment
The 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.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
remove `preventSubdomainRedirection
private redirectToBzzReference(bzzReference: string, tabId: number, preventSubdomainRedirection = false) { | |
private redirectToBzzReference(bzzReference: string, tabId: number) { |
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.
LGTM!
#96 #97 #98