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

Create Browser gateway #11

Open
vasco-santos opened this issue Apr 6, 2018 · 9 comments
Open

Create Browser gateway #11

vasco-santos opened this issue Apr 6, 2018 · 9 comments
Assignees

Comments

@vasco-santos
Copy link
Member

More information will be availble from the OKRs

@vasco-santos vasco-santos self-assigned this Apr 7, 2018
@linonetwo
Copy link

I've implemented a naive one https://github.com/linonetwo/ipfs-browser-gateway, but I'm not familiar with ipfs' DAG traversal, so I stopped there.

Can you give me some advice, so I can make PR here?

@daviddias
Copy link
Member

@linonetwo that's super cool! What we want is to mimic the IPFS HTTP Gateway that one gets when spawning a daemon but through a service worker http proxy.

Why did you need DAG Traversal? The HTTP Gateway only operates over Files. Could you give me an example?

@linonetwo
Copy link

linonetwo commented Apr 23, 2018

Besides adding a single file, people would serve the website and add folders too.
For example, https://ipfs.io/ipfs/QmeYxwj4CwCeGVhwi3xLrmBZUUFQdftshSiGLrTdTnWEVV is a folder. I thought they were added by ipfs-unixfs, thus properly reading them needs traversal of DAG.

When I node.files.get this hash, I got an array of object that has depth, but I was not clear whether this is related to DAG.
https://github.com/linonetwo/ipfs-browser-gateway/blob/master/public/serviceWorker.js#L67-L76

https://ipfs.io/ipfs/QmRoYXgYMfcP7YQR4sCuSeJy9afgA5XDJ78JzWntpRhmcu seems to be another kind of folder. And use node.files.get on it will get huge data. ipfs.io gateway seems to deal with these two kinds of folders differently.

@diasdavid Maybe I need to read the code in the ipfs daemon?

@daviddias
Copy link
Member

@linonetwo
Copy link

linonetwo commented May 6, 2018

Thanks, I know how it works now.

I can reuse /src/http/gateway/resolver.js and copy some core parts of /src/http/gateway/resources/gateway.js if ipfs/src/http/gateway/resolver is exported and browserifyed.

But I didn't find a way to properly import ipfs/http/gateway/resolver.js into service worker now, so I have just copied them.

Most depended npm package was replaced by importScripts( CDN URL ). But some of them use exports internally, so I import them in following ways:

  1. some packages can use this hack to import, but packages with const xxx = require can't
  2. I use https://wzrd.in/standalone/xxxpackage to browserify const xxx = require on the fly, this may be slow since it's not a professional CDN

And I'm still learning how to return a stream from service worker, so still WIP.

@linonetwo
Copy link

It's mostly finished, but:

  1. loading dependencies by importScripts synchronously is slow (10s)
  2. it's not returning a Response, there is a bug, but I'm too sleepy to figure out, it's too late

Hope somebody can review it, it's mostly the same as https://github.com/ipfs/js-ipfs/tree/master/src/http/gateway

@vasco-santos
Copy link
Member Author

vasco-santos commented May 7, 2018

@linonetwo I have already been working on this issue, so thanks for your contribution. I will analyse your implementation asap

@daviddias
Copy link
Member

Repo for the service-worker-gateway project.

@linonetwo
Copy link

@vasco-santos Thank you too. I'm eager to discuss with you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants