I made sample dapp application for interacting with smart contract and i developed a basic ui when i am publishing it to ipfs like i did seeing a tutorial and ipfs documentation, i can get only index.html file and supporting scripts and css files are throwing error file not found. can any pls help me out in this issue.
-
Hi there. What did you see in the tutorial, and exactly what commands have you tried? What is the error being output?– Richard HorrocksCommented Jan 28, 2019 at 9:19
-
i used ipfs add -r <my-directory> command and took my directory hash and published on the browser url. I am getting net::ERR_ABORTED 404 for all my files in chrome console.– Prasanth A SCommented Jan 28, 2019 at 10:08
1 Answer
Most probably you're linking to the resources the wrong way. Make sure you're referring to your resources with relative URLs, so instead of doing <script src="/my-script.js"></script>
(absolute link) you do <script src="./my-script.js"></script>
(relative link).
This is because a IPFS website could be loaded in many contexts. Linking to ./my-script.js
would work correctly at all times while absolute would work in some but not all.
Some examples:
Development context, you load http://localhost:3000
, /my-script.js
(absolute) works alright because your website root is localhost:3000
.
Gateway context, you load http://ipfs.io/ipfs/$yourHash
, now /my-script.js
would not work, as then it tries to load from http://ipfs.io/my-script.js
instead of http://ipfs.io/ipfs/$yourHash/my-script.js
. Relative link fixes that.
Dnslink context, you load http://example.com
, again /my-script.js
would work correctly, because your website root is example.com
.
So verify your resource links are actually relative. If they already are, please post your code so we can look into it further.