Smallweb 0.12 - Publish and install flow for smallweb apps
by Achille Lacoin
3 min read
Smallweb 0.12 is out! And it's the first release since 0.8 where I do not feel the need to fondamentally change the routing system 😅.
But this is still a big release! And it even contains a few breaking changes (don't worry, they are easy to fix).
smallweb install
: A new convention to install and publish smallweb apps
Smallweb now includes a new smallweb install
command to install smallweb apps from the web.
Smallweb apps work on top of github repositories. When you run
smallweb install pomdtr/example-app ~/localhost/smallweb-app
smallweb will clone the pomdtr/example-app
repository in the ~/localhost/smallweb-app
folder.
If the repository contains a smallweb
branch, smallweb will checkout this branch. Otherwise, it will checkout the main
branch.
This convention is really similar to how github pages work, and you can even repurposes github pages actions to build your smallweb app (see how this blog is built for an example).
Once an app is installed, you can use the git
cli to manage them. For example, you can run git pull
to update the app to the latest version, or git checkout <hash>
to rollback to a previous version. Take a look to the pomdtr/smallweb-puller repository for a simple way to trigger an app update from the ouside.
If you create a smallweb app, make sure to add the smallweb-app
topic to your repository.
smallweb init
now support custom templates
The smallweb init
was reworked to allow users to define custom templates from github. Smallweb templates are just github repositories with a smallweb-template
topic.
The new command usage is:
smallweb init [dir] [--template <repo>]
When you run smallweb init example --template pomdtr/smallweb-template-astro
, smallweb will download the content of the pomdtr/smallweb-template-astro
repository in the example
folder (without creating a .git
folder).
Crons jobs are now defined as HTTP requests
Crons uses to be defined as shell commands:
{
"crons": [
{
"schedule": "0 0 * * *",
"command": "deno",
"args": ["run", "--allow-net", "https://example.com/cron.ts"]
}
]
}
This had a few limitations:
- crons did not respect the permissions of the app
- getting access to the same Deno KV instance was tricky in some cases
For these reasons (and in preparation for the upcoming hosted version of smallweb), crons are now defined as HTTP requests:
// smallweb.json
{
"crons": [
{
"schedule": "0 0 * * *",
"path": "/refresh",
}
]
}
This is the exact same API as Vercel's cron, so you can refer to their documentation for some examples of how to use it.
This also remove the need for the smallweb cron trigger
command (as you can just go to https://<app>/refresh
to trigger the cron).
smallweb cron list
was moved to smallweb crons
.
smallweb open
has new flags
Smallweb open now supports opening both using the app name or dir:
# open the react.localhost app
smallweb open --app react.localhost
# open the located at ~/localhost/react
smallweb open --dir ~/localhost/react
# open the current directory
smallweb open
Deno KV is now scoped to the hostname
If you map multiple domains to the same dir:
{
"*-kv.smallweb.run": "~/kv"
}
And uses the default KV instance:
// ~/kv/main.ts
const kv = await Deno.openKv()
example-kv.smallweb.run
and another-kv.smallweb.run
will not share the same KV instance. This behavior will allow some cool new usecases (ex: preview deployments with distinct KV instances).
If you want to share a db between multiple hostnames, you can always specify a kv path in your code:
const kv = await Deno.openKv({ path: "./kv.db" })
What's next?
I really feel smallweb is in a good state right now, and I want to grow its community. I just bought a new mic and plan to record some videos to showcase smallweb features on YouTube and Twitter.
Improved logs are still a priority. I want to move logs to their own file instead of using stderr/stdout, and allow you to filter them by app/time by storing them as JSON lines.
Now that we have an efficient way to distribute and install apps, I want to port more apps to smallweb. I hope you'll help me with this one!
And finally, I plan to resume the work on smallweb sister project, smallbrowser.