├── LICENSE ├── README.md ├── example.html ├── index.html └── script.js /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Pierre-Jean Bergeron 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # serverless-p2p-hosting 2 | 3 | A minimalist serverless P2P web hosting. 4 | 5 | Idea from [Gabe Durazo](https://twitter.com/losvedir). Implemented using [webtorrents](https://github.com/feross/webtorrent). 6 | -------------------------------------------------------------------------------- /example.html: -------------------------------------------------------------------------------- 1 |

Welcome to P2P Serverless Hosting

2 | 3 |

Look, no server!

4 | 5 |

This web page is hosted on no server and was downloaded directly from the browser of someone currently viewing it.
You're now a part of the network and someone who loads this page in the future may get it from you!

6 | 7 |

There is no server, so as soon as the last person (or peer) closes their browser, it's gone.

8 | 9 |

Now, try to create a page

10 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | P2P Serverless Hosting 6 | 7 | 12 | 13 | 14 |
15 | 35 |
36 | 37 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /script.js: -------------------------------------------------------------------------------- 1 | $(document).ready(function() { 2 | var client = new WebTorrent() 3 | 4 | if (window.location.hash) { 5 | $('#content-goes-here').html('Downloading page from seeds...'); 6 | $('#new-page').show() 7 | client.add('magnet:?xt=urn:btih:' + document.URL.substr(document.URL.indexOf('#') + 1) + '&tr=wss%3A%2F%2Ftracker.btorrent.xyz&tr=wss%3A%2F%2Ftracker.fastcast.nz&tr=wss%3A%2F%2Ftracker.openwebtorrent.com', function (torrent) { 8 | swarm = torrent.swarm 9 | 10 | $('#seeds-count').html(swarm.wires.length + 1) 11 | 12 | swarm.on('wire', function(wire) { 13 | $('#seeds-count').html(swarm.wires.length + 1) 14 | }); 15 | 16 | var file = torrent.files[0] 17 | 18 | file.getBuffer(function (err, buffer) { 19 | if (err) throw err 20 | $('#content-goes-here').html(buffer.toString('utf8')) 21 | }) 22 | }); 23 | } 24 | else 25 | { 26 | $('#new-page').show() 27 | 28 | $("form").submit(function(e) { 29 | e.preventDefault(); 30 | 31 | var f = new File([$('#new-page-content').val()], "html"); 32 | 33 | $('#content-goes-here').html($('#new-page-content').val()) 34 | 35 | client.seed(f, function onseed (torrent) { 36 | magnetURI = torrent.magnetURI.split(':')[3].split('&')[0] 37 | document.location.hash = magnetURI; 38 | 39 | swarm = torrent.swarm 40 | 41 | swarm.on('wire', function(wire) { 42 | $('#seeds-count').html(swarm.wires.length + 1) 43 | }); 44 | }); 45 | return false; 46 | }); 47 | } 48 | }) 49 | --------------------------------------------------------------------------------