diff --git a/index.html b/index.html index 5950de3..0e80d38 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,6 @@ - + diff --git a/package.json b/package.json index abda72d..07338ce 100644 --- a/package.json +++ b/package.json @@ -3,6 +3,7 @@ "version": "1.0.0", "description": "Bundle js-ipfs with WebPack", "scripts": { + "build": "node node_modules/.bin/webpack -p && cp index.html dist/index.html", "start": "node server.js" }, "license": "MIT", diff --git a/src/fetcher.js b/src/fetcher.js index 783f5c9..e4f019a 100644 --- a/src/fetcher.js +++ b/src/fetcher.js @@ -81,13 +81,8 @@ self.addEventListener('fetch', (event) => { const request_path = (new URL(event.request.url)).pathname - // If this isn't an IPFS URL, bail. - if (!request_path.startsWith('/ipfs/')) { - console.log('not a valid IPFS hash:', request_path) - if (request_path != '/bundle.js' && request_path != '/fetcher.js') { - event.respondWith(not_found_response()) - } - return + if (request_path == '/ipfs/bundle.js' || request_path == '/ipfs/fetcher.js') { + return console.log('skipping bundles') } // If this is a same-origin or CORS request, and it's not to a URL within the same base IPFS diff --git a/src/index.js b/src/index.js index 1842fc6..035280e 100644 --- a/src/index.js +++ b/src/index.js @@ -10,13 +10,15 @@ function App() { function create() { if ('serviceWorker' in navigator) { - navigator.serviceWorker.register('/fetcher.js') + navigator.serviceWorker.register('/ipfs/fetcher.js') .then((registration) => { console.log('registered the service worker successfully') // Now that a service worker is registered to intercept URLs, reload the page so // this page's URL gets loaded from IPFS by the service worker. - window.location.reload(false) + if (window.location.pathname.startsWith('/ipfs/')) { + window.location.reload(false) + } }) .catch((err) => { console.log('failed to register the service worker:', err) diff --git a/webpack.config.js b/webpack.config.js index b04e1d0..5aca323 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -14,7 +14,7 @@ module.exports = { path: path.join(__dirname, 'dist'), filename: '[name].js', sourceMapFilename: '[name].js.map', - publicPath: '/' + publicPath: '/ipfs/' }, plugins: [ // new UglifyJSPlugin()