Skip to content

Commit 1445efd

Browse files
committed
push
1 parent 3e2b6c6 commit 1445efd

File tree

5 files changed

+413
-299
lines changed

5 files changed

+413
-299
lines changed

docs/develop/dynamic-content.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ id: dynamic-content
44
sidebar_label: Dynamic Content
55
---
66

7+
:::warning
8+
Under construction, set for major revisions to incorporate content from manifests, rout, and host your website pages
9+
:::
10+
11+
712
## Feeds for Dynamic Content
813

914
:::info
@@ -144,3 +149,5 @@ This gives you a fully working dynamic SPA with lightweight incremental updates.
144149
- This keeps deployments fast while ensuring long‑lived URLs remain valid.
145150

146151
The next section (not included here) expands this into a registry‑based system for large dynamic sites.
152+
153+

docs/develop/host-your-website.md

Lines changed: 0 additions & 285 deletions
Original file line numberDiff line numberDiff line change
@@ -480,288 +480,3 @@ This works across:
480480
481481
You do not need to encode the hash or use any additional tools. `bzz://<hash>` is sufficient.
482482
483-
## Client-Side Routing
484-
485-
This section explains how to add hash based client side routing to your Swarm hosted site so that you can have clean URLs for each page of your website. See the [routing project in the examples repo](https://github.com/ethersphere/examples/tree/main/routing) for a full working example implementation.
486-
487-
### Why Hash Based Client Side Routing?
488-
489-
Swarm does not behave like a traditional web server — there is **no server-side routing**, and every route must correspond to a real file inside the site manifest.
490-
If you try to use typical "clean URLs" like:
491-
492-
```
493-
/about
494-
/contact
495-
/dashboard/settings
496-
```
497-
498-
Swarm will look for literal files such as:
499-
500-
```
501-
about
502-
contact
503-
dashboard/settings
504-
```
505-
506-
...which obviously don’t exist unless you manually manipulate the manifest.
507-
This is theoretically possible, but is tricky and complex to do manually, and there is currently not (yet) any tooling to make it easier.
508-
509-
### How to Add Routing
510-
511-
If you want multiple pages on a Swarm-hosted website, you should use a client-side router. Swarm has no server backend running code and so can’t rewrite paths, so we use **React Router’s `HashRouter`**, which keeps all routing inside the browser.
512-
513-
Below is the simplest way to set this up using **create-swarm-app** and then adding your own pages.
514-
515-
516-
#### 1. Create a New Vite + React Project (with `create-swarm-app`)
517-
518-
Run:
519-
520-
```bash
521-
npm init swarm-app@latest my-dapp-new vite-tsx
522-
```
523-
524-
This generates a clean project containing:
525-
526-
```
527-
src/
528-
App.tsx
529-
index.tsx
530-
config.ts
531-
public/
532-
index.html
533-
package.json
534-
```
535-
536-
You now have a fully working Vite/React app ready for Swarm uploads.
537-
538-
539-
#### 2. Install React Router
540-
541-
Inside the project:
542-
543-
```bash
544-
npm install react-router-dom
545-
```
546-
547-
This gives you client-side navigation capability.
548-
549-
550-
551-
#### 3. Switch the App to Use Hash-Based Routing
552-
553-
Swarm only serves literal files, so `/#/about` is the only reliable way to have “pages.”
554-
555-
Replace your `App.tsx` with:
556-
557-
```tsx
558-
import { HashRouter, Routes, Route, Link } from 'react-router-dom'
559-
import { Home } from './Home'
560-
import { About } from './About'
561-
import { NotFound } from './NotFound'
562-
563-
export function App() {
564-
return (
565-
<HashRouter>
566-
<nav style={{ display: 'flex', gap: '12px', padding: '12px' }}>
567-
<Link to="/">Home</Link>
568-
<Link to="/about">About</Link>
569-
</nav>
570-
571-
<Routes>
572-
<Route path="/" element={<Home />} />
573-
<Route path="/about" element={<About />} />
574-
<Route path="*" element={<NotFound />} />
575-
</Routes>
576-
</HashRouter>
577-
)
578-
}
579-
```
580-
581-
This gives you usable routes:
582-
583-
```
584-
/#/ → Home
585-
/#/about → About
586-
/#/anything → React 404 page
587-
```
588-
589-
#### 4. Add Your Page Components
590-
591-
Example `Home.tsx`:
592-
593-
```tsx
594-
export function Home() {
595-
return (
596-
<div style={{ padding: '20px' }}>
597-
<h1>Home</h1>
598-
<p>Welcome to your Swarm-powered app.</p>
599-
</div>
600-
)
601-
}
602-
```
603-
604-
Example `About.tsx`:
605-
606-
```tsx
607-
export function About() {
608-
return (
609-
<div style={{ padding: '20px' }}>
610-
<h1>About</h1>
611-
<p>This demo shows how to upload files or directories to Swarm using Bee-JS.</p>
612-
</div>
613-
)
614-
}
615-
```
616-
617-
Example `NotFound.tsx`:
618-
619-
```tsx
620-
export function NotFound() {
621-
return (
622-
<div style={{ padding: '20px' }}>
623-
<h1>Page Not Found</h1>
624-
<a href="./#/">Return to Home</a>
625-
</div>
626-
)
627-
}
628-
```
629-
630-
#### 5. Add a Static `404.html` for Non-Hash URLs
631-
632-
Swarm still needs a fallback for URLs like:
633-
634-
```
635-
/non-existent-file
636-
```
637-
638-
Create `public/404.html`:
639-
640-
```html
641-
<!DOCTYPE html>
642-
<html>
643-
<head>
644-
<meta charset="UTF-8" />
645-
<title>404 – Not Found</title>
646-
<style>
647-
body { font-family: sans-serif; padding: 40px; }
648-
a { color: #007bff; }
649-
</style>
650-
</head>
651-
652-
<nav style="display: flex; gap: 12px; padding: 12px">
653-
<a href="./#/">Home</a>
654-
<a href="./#/about">About</a>
655-
</nav>
656-
657-
<body>
658-
<h1>404</h1>
659-
<p>This page doesn't exist.</p>
660-
<p><a href="./#/">Return to Home</a></p>
661-
</body>
662-
</html>
663-
```
664-
665-
Vite will automatically include this in `dist/`.
666-
667-
This file handles **non-hash** missing paths.
668-
React handles **hash** missing paths.
669-
670-
671-
#### 6. Build the Project
672-
673-
Before uploading, compile the Vite app into a static bundle:
674-
675-
```bash
676-
npm run build
677-
```
678-
679-
This produces a `dist/` folder containing:
680-
681-
```
682-
dist/
683-
index.html
684-
404.html
685-
assets/
686-
```
687-
688-
Everything inside `dist/` will be uploaded to your Swarm feed.
689-
690-
#### 7. Create a Publisher Identity and Deploy Using a Feed Manifest
691-
692-
For stable URLs, use a **feed manifest** reference. This gives you a permanent Swarm URL that always resolves to the latest version of your content.
693-
694-
Create an identity (if you don’t have one yet):
695-
696-
```bash
697-
swarm-cli identity create web-publisher
698-
```
699-
700-
Upload your built site to the feed:
701-
702-
703-
<Tabs>
704-
<TabItem value="linux" label="Linux / macOS">
705-
706-
```bash
707-
swarm-cli feed upload ./dist \
708-
--identity web-publisher \
709-
--topic-string website \
710-
--stamp <BATCH_ID> \
711-
--index-document index.html \
712-
--error-document 404.html
713-
```
714-
715-
</TabItem>
716-
<TabItem value="powershell" label="Windows PowerShell">
717-
718-
```powershell
719-
swarm-cli feed upload .\dist `
720-
--identity web-publisher `
721-
--topic-string website `
722-
--stamp 3d98a22f522377ae9cc2aa3bca7f352fb0ed6b16bad73f0246b0a5c155f367bc `
723-
--index-document index.html `
724-
--error-document 404.html
725-
```
726-
</TabItem>
727-
</Tabs>
728-
729-
730-
The output includes:
731-
732-
* the **content hash**
733-
* the **feed manifest URL**this is your **permanent website URL**
734-
* stamp usage details
735-
736-
Example:
737-
738-
```
739-
Feed Manifest URL:
740-
http://localhost:1633/bzz/<feed-manifest-hash>/
741-
```
742-
743-
This URL never changes, even when you update your site.
744-
745-
746-
#### 8. Visit Your Site
747-
748-
* Home:
749-
`/#/`
750-
751-
* About:
752-
`/#/about`
753-
754-
* Invalid hash route: handled by `NotFound.tsx`
755-
756-
* Invalid non-hash route: handled by `404.html`
757-
758-
759-
#### Summary
760-
761-
You now have:
762-
763-
* A Vite + React app
764-
* Hash-based routing fully compatible with Swarm
765-
* A static 404 for non-hash paths
766-
* A React 404 for invalid hash paths
767-
* Stable, versioned deployments using feed manifests
Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
---
2-
title: Directories & Routing (Manifests)
3-
id: directories-routing
4-
sidebar_label: Directories & Routing
2+
title: Manifests ("Virtual Filesystem")
3+
id: manifests
4+
sidebar_label: Manifests ("Virtual Filesystem")
55
---
66

77
import Tabs from '@theme/Tabs';
88
import TabItem from '@theme/TabItem';
99

1010
Bee nodes — along with tools used for working with them like `bee-js` and `swarm-cli` — let you upload whole folders of files to Swarm.
1111

12-
Swarm doesn’t have a traditional filesystem, but can _act like one_ using **manifests**, which map readable paths (like `/images/cat.jpg`) to immutable Swarm references.
12+
Swarm doesn’t technically have a filesystem, but can *act like one* using **manifests**, which map readable paths (like `/images/cat.jpg`) to immutable Swarm references.
1313

1414
:::info
1515
The `bee-js` [`MantarayNode` class](https://github.com/ethersphere/bee-js?tab=readme-ov-file#swarm-primitives) is the main way to work with manifests in NodeJS.
@@ -213,13 +213,16 @@ Instead, download files by using the top-level directory manifest and the file
213213

214214
Example:
215215

216-
````bash
216+
```bash
217217
curl http://127.0.0.1:1633/bzz/4d5e6e3eb532131e128b1cd0400ca249f1a6ce5d4005c0b57bf848131300df9d/folder/subfolder/deep.txt
218-
:::
218+
```
219+
220+
Terminal output:
219221

220222
```bash
221223
DEEP
222-
````
224+
```
225+
:::
223226

224227
**Metadata:**
225228

@@ -266,7 +269,7 @@ This means:
266269

267270
Meanwhile, `"folder/"` has **no file itself**, so its target is zero.
268271

269-
## Directories (bee-js)
272+
## Manipulating Directories
270273

271274
In this section we explain how to inspect and modify manifests for non-website directories. You can find the completed [example scripts on GitHub](https://github.com/ethersphere/examples/tree/main/manifests).
272275

@@ -739,9 +742,4 @@ Now the file appears under:
739742
740743
Note that the only new method we used was `node.removeFork()` to remove the entry from the manifest.
741744
742-
```js
743-
// STEP 1 — Remove /new.txt
744-
node.removeFork("new.txt")
745-
console.log("Removed /new.txt from manifest.")
746-
```
747745

0 commit comments

Comments
 (0)