📜 ⬆️ ⬇️

We host a site in the interplanetary IPFS file system under Windows

Some time has passed since the beginning of my experiments with hosting simple sites in IPFS. I launched my IPFS client under Windows and now I have something to add to the previous article "Publish a site in the interplanetary IPFS file system"


  1. Solution of the problem with utf-8 in the Windows XP console.
  2. Its page 404
  3. Correct site loading from different URLs

Let me remind you: InterPlanetary File System is a new decentralized file sharing network (HTTP-server, Content Delivery Network ). About her, I began the story in the article "Interplanetary File System IPFS" .

image



Before the start


You need to create a shortcut on ipfs.cmd file in the properties of which change the font on the Lucida Console. This will make it possible to switch to UTF-8.


Running IPFS under Windows


I want to see what requests come to our client. Use the batch file. It will set up console output, variables, and use findstr or grep to filter the client’s IPFS output.


For Windows 7 and newer


File: ipfs.cmd


rem   UTF-8 (>= Windows 7) chcp 65001 rem         Windows SET IPFS_LOGGING_FMT=nocolor rem |-D -   DEBUG          rem |listening -    rem |namesys -     rem |path -       ipfs.exe daemon -D 2>&1|findstr "listening namesys path" 2>nul pause 

For Windows XP


In Windows XP, there is a feature that by trying to switch to utf-8 in the command file, execution ends immediately. Through trial and error I managed to switch the encoding in the batch file.


start "utf-8" /B cmd /C chcp 65001


But it turned out the team must work during the program. And it is necessary to return the encoding at the end of the command.


After I "discovered" the way to switch, I found other solutions .


chcp 65001 | ipfs daemon & chcp 1251


Thus, switching to utf-8 is performed while ipfs is running. And when ipfs ends, the encoding switches to win1251 and the bat file continues to work.


We will need Grep for Windows . Findstr is cut down when UTF-8 is enabled from the first line in which Cyrillic characters are present. Well, it displays points for the place.


File: ipfs.cmd


 rem         Windows SET IPFS_LOGGING_FMT=nocolor rem |  UTF-8 (Windows XP) rem |-D -   DEBUG          rem |listening -    rem |namesys -     rem |path -       chcp 65001|ipfs.exe daemon -D 2>&1|grep "listening\|namesys\|path" 2>nul & chcp 1251 pause 

404 Not Found (manifest.appcache)


There is no 404 custom page in IPFS. We can imitate it with appcache.


File: manifest.appcache


 CACHE MANIFEST # 2017-03-29 v1.0 #    404.html CACHE: 404.html #       404   FALLBACK: / 404.html #       NETWORK: * 

When using appcache, you cannot set the Expiries header for pages on which manifest.appcache and resources specified in the manifest in the CACHE section are declared. When updating the manifest.appcache file, Firefox "updates" the files specified in the manifest from its own cache than it will leave old files with the updated manifest.


The pages can not be specified in the base tag <base href="https:///" /> which leads to another domain. Firefox supplements the path to the manifest file with the value of the href property of the base tag and blocks the loading of manifest.appcache if it is on a different domain or protocol (http -> https).


Other nuances: "Basic pitfalls when using cache in HTML5 applications"


URLs Relative paths to resources


External page resources should be indicated by relative paths. Site content in IPFS can be downloaded from a variety of different url of varying degrees of nesting.


 http:///.html http://ipfs.io/ipns//.html http://ipfs.io/ipns/__/.html http://ipfs.io/ipfs/_/.html    http://ipfs.io/ipfs/_ 

For the latter case, it is better to include css and js in the page. Or include a script that will handle this case and put the correct links to resources and pages.


Also, instead of "ipfs.io" or a domain in the address can be:


  1. localhost:8080
  2. 127.0.0.1:8080
  3. [::1]:8080
    and so on.

As a result, we will have such a page.


File: index.html


 <!doctype html> <!--     manifest --> <html manifest="manifest.appcache"> <head> <meta charset="utf-8" /> <title> </title> <script> if (window.location.hash.substr(1,8) == "magnet:?"){ var magnet = document.location.hash.substr(9) //      setTimeout(function() {window.location.replace("magnet-converter/#magnet:?"+magnet);}, 0); } </script> </head> <body> <!--     href --> <a href="magnet-converter/">magnet converter</a> <a href="gravity/gravity.svg">gravity</a> <a href="https://github.com/ivan386?tab=repositories">All projects</a> <!--     src --> <img src="imgs/stars-static.svg" style="display: block; width: 100%" /> </body> </html> 

Ipfs as a mirror


It is not necessary to use the IPFS client as an HTTP server. You can use any HTTP-server that will give the contents of the site if the visitor does not have an IPFS client installed. In IPFS you can download a mirror of this site.


Conclusion


He told that he remembered. I hope this is not enough. There is an idea for the implementation of deduplication and speeding up the classic Internet through IPFS. I hope to talk about this in future articles with working examples.


My releases of an IPFS client with fixes on github :


  1. Compatible with punycode.
  2. Etag for all GET requests.
  3. Correct detection of hidden files in Windows.

Sources


  1. ipfs command reference
  2. Documentaion for logging?
  3. grep in windows? Easy!
  4. What is grep and what it eats
  5. Grep for windows
  6. Using the application cache
  7. The main pitfalls when using cache in HTML5 applications
  8. chcp 65001 and a .bat file

')

Source: https://habr.com/ru/post/325176/


All Articles