Skip to content

Commit c080fe2

Browse files
committed
improve readme
1 parent 0862fac commit c080fe2

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

README.md

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,23 @@ Smallweb is obsessed with scaling down. No dev server or a build is required, an
88

99
Let's say I want to self-host my own drawing app.
1010

11-
```bash
12-
# the app subdomain will be draw.<your-domain>
11+
First, I'll create a folder for my app:
12+
13+
```ts
1314
mkdir -p ~/smallweb/draw
15+
```
16+
17+
Then, I'll create a `main.ts` file in that folder:
1418

15-
# Smallweb apps can be contained in a single file
16-
cat <<EOF > ~/smallweb/draw/main.ts
19+
```ts
20+
// ~/smallweb/draw/main.ts
1721
import { Excalidraw } from "jsr:@smallweb/excalidraw@0.9.1";
1822

1923
const excalidraw = new Excalidraw({
2024
rootDir: "./data"
2125
});
2226

2327
export default excalidraw;
24-
EOF
2528
```
2629

2730
And voila! No need to run a single command, your website is already available at `https://draw.<your-domain>`! And each time the drawing is modified, it get automatically persited to `~/smallweb/draw/data/drawing.json`.
@@ -43,18 +46,22 @@ Smallweb tries to keep it's api as simple as possible. The only requirement is t
4346

4447
export default {
4548
fetch: (request: Request) => {
46-
return new Response("Example server!");
49+
return new Response("Handling request!");
50+
},
51+
run: (_args: string[]) => {
52+
console.log("Running command!");
53+
},
54+
email: (_msg: ReadableStream) => {
55+
console.log("Received email!");
4756
},
48-
run: () => {
49-
console.log("Example cli!");
50-
}
5157
}
5258
```
5359

5460
You can invoke:
5561

5662
- the `fetch` function by send a request to `https://example.<your-domain>`
5763
- the `run` function by running `smallweb run example` or `ssh example@<your-domain>`
64+
- the `email` function by sending an email to `example!<your-domain>`
5865

5966
Of course, it is super easy to hook these functions to a web framweork like [hono](https://hono.dev) or a cli framework like [commander](https://www.npmjs.com/package/commander).
6067

0 commit comments

Comments
 (0)