Skip to content
This repository has been archived by the owner on Mar 26, 2024. It is now read-only.

Merge branch 'master' of linonetwo/ipfs-browser-gateway #1

Closed
wants to merge 51 commits into from
Closed
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
25299e5
Initial commit
Mar 18, 2018
28f8926
feature: add three pages
Mar 18, 2018
a41699e
feature: set up ipfs
Mar 18, 2018
5de36f8
feature: print files to dom
Mar 20, 2018
126b7f7
doc: how to use
Mar 20, 2018
94fb13d
feature: add basic service worker
Mar 27, 2018
121ff8f
feature: add component to show result from file.get
Mar 27, 2018
1c4fb31
feature: register sw
Mar 27, 2018
d4a3128
refactor: just move code to registerServiceWorker.js
Mar 27, 2018
105e37a
chore: delete page side IPFS code
Mar 27, 2018
572b538
bugfix: should move service worker to /public
Mar 27, 2018
e6a763e
feature: seems I can't load ipfs from node_modules but fron CDN
Mar 27, 2018
7eac6d6
feature: user file.get
Mar 27, 2018
f464dbc
feature: log files out, seems the log from page will only show up aft…
Mar 27, 2018
611885b
feature: try return a HTML file from IPFS
Mar 27, 2018
0c3424e
feature: try add file to cache
Mar 28, 2018
d45dda0
feature: correctly return multiple files in a DAG
Mar 28, 2018
2dd1411
doc: add detailed comment
Mar 28, 2018
b5cba57
doc: add Readme
Mar 28, 2018
92fd12e
doc: do some translation
Mar 28, 2018
f6e1671
feature: copy DAG-traversal from js-ipfs and start a rewirting
May 6, 2018
d3538c5
chore: upgrade deps, add eslint, rewire CRA
May 6, 2018
b51c574
feature: port main part of ipfs-gateway here
May 6, 2018
d811367
feature: rewrite all require() to importScripts()
May 6, 2018
705bb4c
lint: rearrange code
May 6, 2018
2ae9498
feature: rewrite stream
May 6, 2018
a11dc86
doc: new road map
May 6, 2018
5c48b4c
feature: redirect
May 6, 2018
7245d56
feature: pass path to main function
May 6, 2018
b0b9816
refactor: remove cache, if index.html ask for a style.css, just trave…
May 6, 2018
6c3b853
doc: add reference
May 6, 2018
2e020fc
feature: port renderFolder() here
May 6, 2018
8fe77b1
bugfix: require is working now
May 6, 2018
39cb1d8
bugfix: there is IpfsUnixfs instead of Unixfs
May 6, 2018
3c24780
bugfix: an object that was not a Response was returned
May 6, 2018
7ac1470
doc: point out that it is slow to load deps
May 6, 2018
4b7cfc8
doc: typo
May 6, 2018
a0cd434
Merge branch 'master' of https://github.com/ipfs-shipyard/service-wor…
May 7, 2018
239b4d0
Revert "Merge branch 'master' of https://github.com/ipfs-shipyard/ser…
May 8, 2018
a55c237
refactor: not need to return json, error string is enough
May 8, 2018
4ad4165
bugfix: properly use callback, which is incorrect in ipfs-gateway
May 8, 2018
a1b7b17
bugfix: correct Responce.redirect usage
May 8, 2018
1a83fc4
chore: localize CDN to speed up development
May 8, 2018
c3f1167
bugfix: correct promise usage
May 8, 2018
7fb6552
doc: add another potential drawback
May 8, 2018
bc19ecb
chore: better error logging
May 8, 2018
f719a31
bugfix: properly require browserified deps
May 8, 2018
a7f5f64
bugfix: redirect to /ipfs/xxx
May 8, 2018
1ee1708
refactor: use stream from ipfs.cat, instead of pull stream
May 8, 2018
f72a484
feat: properly resolve stream
May 8, 2018
7deb797
Revert "chore: localize CDN to speed up development"
May 8, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"parser": "babel-eslint",
"extends": [
"airbnb",
"plugin:flowtype/recommended",
"plugin:jest/recommended",
"prettier",
"prettier/flowtype",
"prettier/react",
"prettier/standard"
],
"plugins": ["flowtype", "prettier", "jest"],
"parserOptions": {
"sourceType": "module",
"ecmaFeatures": {
"jsx": true
}
},
"env": {
"es6": true,
"node": true,
"jest/globals": true
},
"rules": {
"comma-dangle": 1,
"arrow-parens": ["off"],
"consistent-return": "off",
"no-underscore-dangle": "off",
"no-unused-expressions": "off",
"flowtype/define-flow-type": 1,
"flowtype/use-flow-type": 1,
"generator-star-spacing": "off",
"import/no-unresolved": "error",
"import/no-extraneous-dependencies": "off",
"no-console": "off",
"promise/no-native": "off",
"no-loop-func": "off",
"guard-for-in": "off",
"react/sort-comp": [
"error",
{
"order": ["type-annotations", "static-methods", "lifecycle", "everything-else", "render"]
}
],
"react/no-multi-comp": "off",
"no-param-reassign": "off",
"no-restricted-syntax": "off",
"max-len": "off",
"react/jsx-no-bind": "off",
"react/jsx-filename-extension": ["error", { "extensions": [".js", ".jsx"] }],
"jsx-a11y/anchor-is-valid": [
"error",
{
"components": [],
"specialLink": ["hrefLeft", "hrefRight"],
"aspects": ["noHref", "invalidHref", "preferButton"]
}
]
},
"globals": {
"window": true,
"document": true
}
}
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
70 changes: 16 additions & 54 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,59 +1,21 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*

# Runtime data
pids
*.pid
*.seed
*.pid.lock

# Directory for instrumented libs generated by jscoverage/JSCover
lib-cov

# Coverage directory used by tools like istanbul
coverage

# nyc test coverage
.nyc_output

# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
.grunt

# Bower dependency directory (https://bower.io/)
bower_components
# See https://help.github.com/ignore-files/ for more about ignoring files.

# node-waf configuration
.lock-wscript
# dependencies
/node_modules

# Compiled binary addons (http://nodejs.org/api/addons.html)
build/Release
# testing
/coverage

# Dependency directories
node_modules/
jspm_packages/
# production
/build

# Typescript v1 declaration files
typings/

# Optional npm cache directory
.npm

# Optional eslint cache
.eslintcache

# Optional REPL history
.node_repl_history

# Output of 'npm pack'
*.tgz

# Yarn Integrity file
.yarn-integrity

# dotenv environment variables file
.env
# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
4 changes: 4 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,8 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
<<<<<<< HEAD
SOFTWARE.
=======
SOFTWARE.
>>>>>>> 4be42007f8b7a1f7f336d2a0398a146f438ea2e6
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,28 @@
# service-worker-gateway

A IPFS gateway fully running on a Service Worker

## Development

This is a "create-react-app" app, so just:

`yarn && yarn start`

## Drawback

1. The first visit is way slower than traditional HTTP page. Though ```http://ipfs.io/ipfs``` is slow too.
1. Can't promise long-term cache, compared to a gateway running on a server, who can pin a file for a longer time.
1. Large folders like [QmRoYXgYMfcP7YQR4sCuSeJy9afgA5XDJ78JzWntpRhmcu](http://ipfs.io/ipfs/QmRoYXgYMfcP7YQR4sCuSeJy9afgA5XDJ78JzWntpRhmcu) may destroy service worker (maybe due to my using ```files.get```), so it's more suitable to just load HTML pages in this way.
1. Don't work with AJAX likes fetch API.
1. Loading dependencies by importScripts synchronously are slow (10s).

## Road Map

- Bundle all dependencies.
- There will be a pull request to [ipfs-service-worker](https://github.com/ipfs/ipfs-service-worker) ones this project is done.

## Reference

- [Discussion](https://github.com/ipfs/ipfs-service-worker/issues/11)
- [JS-IPFS-Gateway](https://github.com/ipfs/js-ipfs/tree/master/src/http/gateway)
- [readable-stream in SW](https://developers.google.com/web/updates/2016/06/sw-readablestreams)
26 changes: 26 additions & 0 deletions config-overrides.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const { injectBabelPlugin } = require('react-app-rewired');

module.exports = function override(config, env) {
config = injectBabelPlugin(
[
'flow-runtime',
{
assert: true,
annotate: true,
},
],
config,
);

if (env === 'production') {
console.log('⚡ Production build with optimization ⚡');
config = injectBabelPlugin('closure-elimination', config);
config = injectBabelPlugin('transform-react-inline-elements', config);
config = injectBabelPlugin('transform-react-constant-elements', config);
}

// remove eslint in eslint, we only need it on VSCode
config.module.rules.splice(1, 1);

return config;
};
40 changes: 40 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"name": "ipfs-browser-gateway",
"version": "0.1.0",
"private": true,
"dependencies": {
"history": "^4.7.2",
"ipfs": "^0.28.2",
"react": "^16.3.2",
"react-dom": "^16.3.2",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-scripts": "1.1.4",
"styled-components": "^3.2.6",
"styled-flex-component": "^2.2.2"
},
"devDependencies": {
"babel-eslint": "^8.2.3",
"babel-plugin-closure-elimination": "^1.3.0",
"babel-plugin-flow-runtime": "^0.17.0",
"babel-plugin-transform-react-constant-elements": "^6.23.0",
"babel-plugin-transform-react-inline-elements": "^6.22.0",
"eslint": "^4.19.1",
"eslint-config-airbnb": "^16.1.0",
"eslint-config-prettier": "^2.9.0",
"eslint-plugin-flowtype": "^2.46.3",
"eslint-plugin-import": "^2.11.0",
"eslint-plugin-jest": "^21.15.1",
"eslint-plugin-jsx-a11y": "^6.0.3",
"eslint-plugin-prettier": "^2.6.0",
"eslint-plugin-react": "^7.7.0",
"flow-typed": "^2.4.0",
"react-app-rewired": "^1.5.2"
},
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test --env=jsdom",
"eject": "react-scripts eject"
}
}
Binary file added public/favicon.ico
Binary file not shown.
40 changes: 40 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="theme-color" content="#000000">
<!--
manifest.json provides metadata used when your web app is added to the
homescreen on Android. See https://developers.google.com/web/fundamentals/engage-and-retain/web-app-manifest/
-->
<link rel="manifest" href="%PUBLIC_URL%/manifest.json">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tags above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<noscript>
You need to enable JavaScript to run this app.
</noscript>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start` or `yarn start`.
To create a production bundle, use `npm run build` or `yarn build`.
-->
</body>
</html>
16 changes: 16 additions & 0 deletions public/mainStyle.js

Large diffs are not rendered by default.

15 changes: 15 additions & 0 deletions public/manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"icons": [
{
"src": "favicon.ico",
"sizes": "64x64 32x32 24x24 16x16",
"type": "image/x-icon"
}
],
"start_url": "./index.html",
"display": "standalone",
"theme_color": "#000000",
"background_color": "#ffffff"
}
38 changes: 38 additions & 0 deletions public/pathUtil.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/* eslint-disable no-unused-vars */
function splitPath(path) {
if (path[path.length - 1] === '/') {
path = path.substring(0, path.length - 1);
}

return path.split('/');
}

function removeLeadingSlash(url) {
if (url[0] === '/') {
url = url.substring(1);
}

return url;
}

function removeTrailingSlash(url) {
if (url.endsWith('/')) {
url = url.substring(0, url.length - 1);
}

return url;
}

function removeSlashFromBothEnds(url) {
url = removeLeadingSlash(url);
url = removeTrailingSlash(url);

return url;
}

function joinURLParts(...urls) {
urls = urls.filter(url => url.length > 0);
urls = [''].concat(urls.map(url => removeSlashFromBothEnds(url)));

return urls.join('/');
}
Loading