···31313232- <https://docs.smallweb.run>
3333- <https://blog.smallweb.run>
3434-- <https://tldraw.smallweb.run>
3434+- <https://excalidraw.smallweb.run>
35353636Since creating smallweb websites is so easy, you can even create super simple ones. For example, when I want to invite someone to the smallweb discord server, I just send him the link <https://discord.smallweb.run>, which maps to `~/smallweb/discord/main.ts` on my vps.
3737
···11-# Getting started
22-33-## Why Smallweb ?
44-55-See <https://smallweb.run> for a quick overview of the project.
66-77-## Installation
88-99-Smallweb installations steps heavily depends on the experience you want to have with Smallweb. Here are a few options:
1010-1111-- [Localhost Setup](./hosting/localhost/localhost.md) - Easiest way to get started, no need for a dedicated server or a domain name. Work on MacOS and Linux.
1212-- [Home Server Setup](./hosting/cloudflare/cloudflare.md) - Host you apps on your home server, and expose them to the internet using Cloudflare Tunnel. Requires a domain name.
1313-- [VPS Setup](./hosting/vps.md) - Similar to the Home Server setup, but using a VPS Provider instead. Shows you how to setup a fresh Debian 12 VPS to host your smallweb apps.
1414-1515-## Usage
1616-1717-Follow the [Routing](./guides/routing.md) guide to learn more about the smallweb folder structure, and create your first app.
-64
docs/src/guides/auth.md
···11-# Private Apps
22-33-You can automatically protects private apps behind a login prompt. In order to achieve this, you'll need to:
44-55-1. Add an `email` field to your global config
66-77- ```json
88- // ~/.config/smallweb/config.json
99- {
1010- "domain": "example.com",
1111- "dir": "~/smallweb",
1212- "email": "pomdtr@example.com"
1313- }
1414- ```
1515-1616-1. Set the private field to true in your app's config.
1717-1818- ```json
1919- // ~/smallweb/private-app/smallweb.json
2020- {
2121- "private": true
2222- }
2323- ```
2424-2525-The next time you'll try to access the app, you'll be prompted with a login screen (provided by lastlogin.net).
2626-2727-Additionaly, you can generate tokens for non-interactive clients using the `smallweb token` create command.
2828-2929-```sh
3030-smallweb token create --description "CI/CD pipeline"
3131-```
3232-3333-Then, you can pass this token in the `Authorization` header of your requests.
3434-3535-```sh
3636-curl https://private-app.example.com -H "Authorization: Bearer <token>"
3737-```
3838-3939-or alternatively, use the basic auth username.
4040-4141-```sh
4242-curl https://private-app.example.com -u "<token>"
4343-4444-# or
4545-curl https://<token>@private-app.example.com
4646-```
4747-4848-If your app is public, but you still want to protect some routes, you can use the `privateRoutes` field in your app's config.
4949-5050-```json
5151-// ~/smallweb/private-app/smallweb.json
5252-{
5353- "privateRoutes": ["/private/*"]
5454-}
5555-```
5656-5757-There is also a `publicRoutes` field that you can use to protect all routes except the ones listed.
5858-5959-```json
6060-{
6161- "private": true,
6262- "publicRoutes": ["/public/*"]
6363-}
6464-```
-40
docs/src/guides/commands.md
···11-# Adding cli commands to your app
22-33-To add a cli command to your app, you'll need to add a `run` method to your app's default export.
44-55-```ts
66-// File: ~/smallweb/custom-command/main.ts
77-export default {
88- run(args: string[]) {
99- console.log("Hello world");
1010- }
1111-}
1212-```
1313-1414-Use `smallweb run` to execute the command:
1515-1616-```console
1717-$ smallweb run custom-command
1818-Hello world
1919-```
2020-2121-## Using a cli framework
2222-2323-[Cliffy](https://cliffy.io/) is an excellent Deno CLI framework that you can use to build more complex CLI applications.
2424-2525-You can easily wire it to smallweb:
2626-2727-```ts
2828-import { Command } from "jsr:@cliffy/command@1.0.0-rc.5";
2929-3030-const name = basename(Deno.cwd());
3131-const command = new Command().name().action(() => {
3232- console.log(`Hello ${name}`);
3333-});
3434-3535-export default {
3636- run(args: string[]) {
3737- await command.parse(args);
3838- }
3939-}
4040-```
-45
docs/src/guides/cron.md
···11-# Cron Tasks
22-33-You can register configure cron tasks from your `smallweb.json[c]`.
44-55-```json
66-{
77- "crons": [
88- {
99- "name": "daily-task",
1010- "schedule": "0 0 * * *",
1111- "args": [],
1212- }
1313- ]
1414-}
1515-```
1616-1717-The schedule field is a cron expression that defines when the task should run. It follows the standard cron syntax, with five fields separated by spaces. You can also use the following shortcuts:
1818-1919-- `@hourly`: Run once an hour, at the beginning of the hour.
2020-- `@daily`: Run once a day, at midnight.
2121-- `@weekly`: Run once a week, at midnight on Sunday.
2222-- `@monthly`: Run once a month, at midnight on the first day of the month.
2323-- `@yearly`: Run once a year, at midnight on January 1st.
2424-2525-In order to handle the cron tasks, your app default export should have a `run` method that will be called when the task is triggered.
2626-2727-```ts
2828-export default {
2929- run(_args: string[]) {
3030- console.log("Running daily task");
3131- }
3232-}
3333-```
3434-3535-If you want to see a list of all cron tasks, you can run:
3636-3737-```sh
3838-smallweb cron ls
3939-```
4040-4141-To trigger one, you can use either the `smallweb cron trigger` or the `smallweb run` command:
4242-4343-```sh
4444-smallweb cron trigger daily-task
4545-```
-33
docs/src/guides/env.md
···11-### Setting env variables
22-33-You can set environment variables for your app by creating a file called `.env` in the application folder.
44-55-Here is an example of a `.env` file:
66-77-```txt
88-BEARER_TOKEN=SECURE_TOKEN
99-```
1010-1111-Use the `Deno.env.get` method to access the environment variables in your app:
1212-1313-```ts
1414-// File: ~/smallweb/demo/main.ts
1515-export default function (req: Request) {
1616- if (req.headers.get("Authorization") !== `Bearer ${Deno.env.get("BEARER_TOKEN")}`) {
1717- return new Response("Unauthorized", { status: 401 });
1818- }
1919-2020- return new Response(`I'm private!`, {
2121- headers: {
2222- "Content-Type": "text/plain",
2323- },
2424- });
2525-}
2626-```
2727-2828-If you want to set an environment variable for all your apps, you can create a `.env` file in the at the root of your smallweb dir.
2929-3030-```json
3131-// ~/smallweb/.env
3232-GLOBAL_VAR=GLOBAL_VALUE
3333-```
-32
docs/src/guides/plugins.md
···11-# Smallweb Plugins
22-33-The smallweb CLI can be extennded with plugins. To create a new plugin, just add a binary to your PATH that starts with `smallweb-` and the CLI will automatically detect it.
44-55-For example, if you create a new `smallweb-choose` file in your PATH with the following content:
66-77-```sh
88-#!/bin/sh
99-1010-# check if fzf is installed
1111-if ! command -v fzy 2> /dev/null
1212-then
1313- echo "fzf could not be found" >&2
1414- echo "Please install fzf to use this script" >&2
1515- echo "Docs: https://github.com/junegunn/fzf?tab=readme-ov-file#installation" >&2
1616- exit 1
1717-fi
1818-1919-smallweb list | cut -f1 | fzf | xargs smallweb open
2020-```
2121-2222-And make it executable with `chmod +x smallweb-choose`, you will be able to run `smallweb choose` and get an interactive list of your apps to choose from, which will then be opened in your default browser.
2323-2424-## Example Plugins
2525-2626-[simpl-site](https://github.com/iamseeley/simpl-site) can be installed as a smallweb plugin. You can install it using the following command:
2727-2828-```sh
2929-deno install -Agf jsr:@iamseeley/simpl-site/smallweb-simpl-site
3030-```
3131-3232-You will then be able to run `smallweb simpl-site` to create a new static site.
-126
docs/src/guides/rest.md
···11-# REST API
22-33-Each smallweb installation comes with a built-in REST API. You can map it to a subdomain by creating a `smallweb.json` manifest:
44-55-```json
66-// ~/smallweb/api/smallweb.jsonc
77-{
88- "entrypoint": "smallweb:api",
99- // make sure to protect your API
1010- "private": true,
1111- "publicRoutes": [
1212- // openapi manifest
1313- "/openapi.json",
1414- // json schemas for config files
1515- "/schemas/*"
1616- ]
1717-}
1818-```
1919-2020-A swagger UI is available at the root of the api, allowing you to easily test the available endpoints.
2121-2222-## Authentication
2323-2424-You'll need to generate a bearer token to access the API. You can create one by running the following command:
2525-2626-```sh
2727-smallweb token create --description "api token" --app <api-subdomain>
2828-```
2929-3030-You'll then be able to use it to authenticate your requests using this token:
3131-3232-```sh
3333-curl https://<api-domain>/v0/apps -H "Authorization: Bearer <token>"
3434-```
3535-3636-Or you can just use the `smallweb api` command, which automatically authenticates your requests:
3737-3838-```sh
3939-smallweb api /v0/apps
4040-```
4141-4242-## Client Library
4343-4444-Since the API is based on OpenAPI, you can easily generate client libraries for your favorite language.
4545-4646-For usage in smallweb apps, I personally recommend using [feTS](https://the-guild.dev/openapi/fets/client/quick-start).
4747-4848-Here is an example of how you can use it (no code-gen required):
4949-5050-```ts
5151-import { createClient, type NormalizeOAS } from 'npm:fets'
5252-import type openapi from 'jsr:@smallweb/openapi@<smallweb-version>'
5353-5454-const client = createClient<NormalizeOAS<typeof openapi>>({
5555- endpoint: Deno.env.get("SMALLWEB_API_URL"),
5656- globalParams: {
5757- headers: {
5858- Authorization: `Bearer ${Deno.env.get("SMALLWEB_API_TOKEN")}`
5959- }
6060- }
6161-})
6262-6363-const res = await client['/v0/apps'].get()
6464-if (!res.ok) {
6565- throw new Error(`Failed to fetch apps: ${res.statusText}`)
6666-}
6767-6868-const apps = await res.json() // typed!
6969-```
7070-7171-## Webdav Server
7272-7373-The rest api bundles a webdav server that you can use to manage your files. It is accessible at: `https://<api-domain>/webdav`.
7474-7575-You can easily connect it to any webdav client:
7676-7777-## Windows
7878-7979-1. Open the File Explorer.
8080-2. Click on the `Computer` tab.
8181-3. Click on `Map network drive`.
8282-4. Enter the URL of the webdav server in the `Folder` field.
8383-5. Click `Finish`.
8484-6. Enter your Smallweb username and password.
8585-7. Click `OK`.
8686-8787-## MacOS
8888-8989-1. Open the Finder.
9090-2. Click on `Go` in the menu bar.
9191-3. Click on `Connect to Server`.
9292-4. Enter the URL of the webdav server in the `Server Address` field.
9393-5. Click `Connect`.
9494-6. Enter your Smallweb username and password.
9595-7. Click `Connect`.
9696-8. Click `Done`.
9797-9898-## Linux (Ubuntu)
9999-100100-1. Open Nautilus / Files.
101101-2. Click on `Other Locations`.
102102-3. Enter the URL of the webdav server, and prefix with `davs://` (ex: `davs://<api-domain>/webdav`).
103103-4. Click `Connect`.
104104-5. Enter your Smallweb username and password.
105105-6. Click `Connect`.
106106-107107-## Android
108108-109109-[Material Files](https://play.google.com/store/apps/details?id=me.zhanghai.android.files) has built-in support for WebDAV.
110110-111111-## Javascript
112112-113113-I'm still searching for a good webdav client in javascript. The best I found so far is [webdav-client](https://www.npmjs.com/package/webdav-client), but I don't really like it.
114114-115115-Still, here is an example of how you can use it:
116116-117117-```ts
118118-import * as webdav from 'webdav'
119119-120120-const webdavClient = webdav.createClient(new URL("/webdav", Deno.env.get("SMALLWEB_API_URL")).href, {
121121- authType: webdav.AuthType.Password,
122122- username: Deno.env.get("SMALLWEB_API_TOKEN")
123123-})
124124-125125-const apps = await webdavClient.getDirectoryContents("/")
126126-```
-23
docs/src/guides/routing.md
···11-# Routing
22-33-Smallweb maps every subdomains of your root domain to a directory in your root directory.
44-55-For example with, the following configuration:
66-77-```json
88-// ~/.config/smallweb/config.json
99-{
1010- "domain": "example.com",
1111- "dir": "~/smallweb"
1212-}
1313-```
1414-1515-The routing system maps domains to directories as follows:
1616-1717-- Direct subdomain mapping:
1818- - `api.example.com` → `~/smallweb/api`
1919- - `blog.example.com` → `~/smallweb/blog`
2020-2121-- Root domain behavior:
2222- - Requests to `example.com` automatically redirect to `www.example.com` if the `www` directory exists
2323- - If the `www` directory does not exist, a 404 error is returned
-21
docs/src/guides/sandbox.md
···11-# App Sandbox
22-33-Smallweb apps have access to:
44-55-- read and write access to their own directory, and the deno cache directory.
66-- access to the network, to make HTTP requests.
77-- access to the env files defined in the global config and in the `.env` file in the app directory.
88-99-This sandbox protects the host system from malicious code, and ensures that apps can only access the resources they need.
1010-1111-## Sharing files between apps
1212-1313-To share files between your apps, just use symbolic links!
1414-1515-For example, if you have two apps `app1` and `app2`, and you want `app2` to have access to the files in the `data` directory of `app1`, you can create a symbolic link in the `app2` directory:
1616-1717-```sh
1818-ln -s $HOME/smallweb/app1/data $HOME/smallweb/app2/data
1919-```
2020-2121-Linking files outside the smallweb directory also work, but it causes issues when syncing the files between different machines, so you should only use it if you only want to edit your files on one machine.
-126
docs/src/guides/server.md
···11-# Hosting Websites
22-33-Smallweb can also host dynamic websites. To create a dynamic website, you need to create a folder with a `main.[js,ts,jsx,tsx]` file in it.
44-55-The file should export a default object with a `fetch` method that takes a `Request` object as argument, and returns a `Response` object.
66-77-```ts
88-// File: ~/smallweb/example-server/main.ts
99-1010-export default {
1111- fetch(request: Request) {
1212- const url = new URL(request.url);
1313- const name = url.searchParams.get("name") || "world";
1414-1515- return new Response(`Hello, ${name}!`, {
1616- headers: {
1717- "Content-Type": "text/plain",
1818- },
1919- });
2020- },
2121-}
2222-```
2323-2424-To access the server, open `https://example-server.localhost` in your browser.
2525-2626-## Using JSX
2727-2828-You can use the `@jsxImportSource` pragma to define the source of the jsx factory function. This allows you to use jsx in your server code.
2929-3030-```tsx
3131-// File: ~/smallweb/jsx-example/main.tsx
3232-/** @jsxImportSource npm:@preact **/
3333-import render from "npm:preact-render-to-string";
3434-3535-const requestHandler = () => new Response(render(<h1>Hello, world!</h1>), {
3636- headers: {
3737- "Content-Type": "text/html",
3838- },
3939-});
4040-4141-export default { fetch: requestHandler };
4242-```
4343-4444-To access the server, open `https://jsx-example.localhost` in your browser.
4545-4646-## Routing Requests using Hono
4747-4848-Smallweb use the [deno](https://deno.com) runtime to evaluate the server code. You get typescript and jsx support out of the box, and you can import any module from the npm and jsr registry by prefixing the module name with `npm:` or `jsr:`.
4949-5050-As an example, the following code snippet use the `@hono/hono` extract params from the request url.
5151-5252-```jsx
5353-// File: ~/smallweb/hono-example/main.ts
5454-5555-import { Hono } from "jsr:@hono/hono";
5656-5757-const app = new Hono();
5858-5959-app.get("/", c => c.text("Hello, world!"));
6060-6161-app.get("/:name", c => c.text(`Hello, ${c.params.name}!`));
6262-6363-// Hono instances have a `fetch`, so they can be used as the default export
6464-export default app;
6565-```
6666-6767-To access the server, open `https://hono-example.localhost` in your browser.
6868-6969-## Static Websites
7070-7171-If your smallweb does not contains a `main.[js,ts,jsx,tsx]` file, Smallweb will serve the folder as a static website.
7272-7373-You can create a website by just adding an `index.html` file in the folder.
7474-7575-```html
7676-<!-- File: ~/smallweb/example-static/index.html -->
7777-<!DOCTYPE html>
7878-<html>
7979- <head>
8080- <title>Example Static Website</title>
8181- </head>
8282- <body>
8383- <h1>Hello, world!</h1>
8484- </body>
8585-</html>
8686-```
8787-8888-To access the website, open `https://example-static.localhost` in your browser.
8989-9090-The static server also supports transpiling `.ts`, `.tsx`, `.jsx`, meaning that you can just import them from your static website.
9191-9292-```html
9393-<!-- ~/smallweb/example-static/index.html -->
9494-<!DOCTYPE html>
9595-<html>
9696- <head>
9797- <title>Example Static Website</title>
9898- </head>
9999- <body>
100100- <div id="root"></div>
101101- <script src="script.tsx"></script>
102102- </body>
103103-```
104104-105105-You'll need to add a pragma to the script file to tell smallweb how to transpile it.
106106-107107-```tsx
108108-// ~/smallweb/example-static/script.tsx
109109-/** @jsxImportSource https://esm.sh/react **/
110110-import { render } from "react-dom";
111111-112112-render(<h1>Hello, world!</h1>, document.getElementById("root"));
113113-```
114114-115115-Only use imports that are usable from the browser. `jsr:` and `npm:` specifiers are not supported in the browser.
116116-117117-If your static website contains a `main.js` file, but you want to serve it as a static website, you can do the following:
118118-119119-- rename it to something else
120120-- create a smallweb.json with the following content:
121121-122122-```json
123123-{
124124- "entrypoint": "smallweb:static"
125125-}
126126-```
docs/src/hosting/cloudflare/apex.png
This is a binary file and will not be displayed.
-73
docs/src/hosting/cloudflare/cloudflare.md
···11-Cloudflare Tunnel is a **free** service that allows you to expose your local server to the internet, without having to expose your local IP address.
22-33-Additionally, it provides some protection against DDoS attacks, and allows you to use Cloudflare's other services like Access.
44-55-## Setup
66-77-1. Make sure that you have a domain name that you can manage with Cloudflare.
88-99-1. Install smallweb on your server, and register it as a service.
1010-1111- ```ts
1212- // install deno
1313- curl -fsSL https://deno.land/install.sh | sh
1414-1515- // install smallweb
1616- curl -sSfL https://install.smallweb.run | sh
1717-1818- // register smallweb as a service
1919- smallweb service install
2020-2121- // make sure that the server service is running
2222- smallweb service status
2323- ```
2424-2525-1. Set the `domain` field in your smallweb config to your domain name.
2626-2727-```sh
2828-# open the smallweb config in your default editor
2929-smallweb config
3030-```
3131-3232-1. From your cloudflare dashboard, navigate to `Zero Trust > Networks > Tunnels`
3333-3434-1. Click on `Create a tunnel`, and select the `Clouflared` option
3535-3636-1. Follow the intructions to install cloudflared, and create a connector on your device.
3737-3838-1. Add a wildcard hostname for your tunnel (ex: `*.<your-domain>`), and use `http://localhost:7777` as the origin service.
3939-4040- 
4141-4242-1. Do the same for your apex domain, if you want to manage it using smallweb.
4343-4444-1. Copy the tunnel ID, and go to `Websites > DNS > Records`.
4545-4646-1. Add a new `CNAME` record for your wildcard hostname, with a target of `<tunnel-id>.cfargotunnel.com`.
4747-4848- 
4949-5050-## Checking that your tunnel is running
5151-5252-Create a dummy smallweb app in `~/smallweb/example`
5353-5454-```sh
5555-mkdir -p ~/smallweb/example
5656-CAT <<EOF > ~/smallweb/example/main.ts
5757-export default {
5858- fetch() {
5959- return new Response("Smallweb is running", {
6060- headers: {
6161- "Content-Type": "text/plain",
6262- },
6363- });
6464- }
6565-}
6666-EOF
6767-```
6868-6969-If everything went well, you should be able to access `https://example.<your-domain>` in your browser, and see the message `Smallweb is running`.
7070-7171-## Optional Steps
7272-7373-- You can protect your tunnel (or specific apps) with Cloudflare Access.
docs/src/hosting/cloudflare/dns.png
This is a binary file and will not be displayed.
docs/src/hosting/cloudflare/tunnel.png
This is a binary file and will not be displayed.
-17
docs/src/hosting/deno-deploy.md
···11-# Deno Deploy
22-33-If one of your websites is starting to get a lot of traffic, you might want to deploy it to a cloud provider.
44-55-Deno Deploy is a cloud platform that allows you to deploy your Deno apps with ease. It's a great choice for smallweb apps, since it's built on top of Deno, and it's very easy to use.
66-77-To deploy an app, you'll just need to:
88-99-1. Install the `deployctl` cli:
1010-1111- ```sh
1212- deno install -Arf jsr:@deno/deployctl
1313- ```
1414-1515-2. Run `deployctl deploy`, and follow the instructions.
1616-1717-Beware, all Deno APIs are not available in Deno Deploy. For example, you won't be able to write files to the filesystem.
···11-This page will guide you through the process of setting up your local environment for smallweb on MacOS.
22-33-This setup is useful for developing and testing smallweb apps locally, without having to deploy them to the internet.
44-55-If you want to expose your apps to the internet instead, you can follow the [Cloudflare Tunnel setup guide](../cloudflare/cloudflare.md).
66-77-## Architecture
88-99-The following diagram illustrates the architecture of the local setup:
1010-1111-
1212-1313-The components needed are:
1414-1515-- a dns server to map `*.localhost` domains to `127.0.0.1` ip address (dnsmasq)
1616-- a reverse proxy to automatically generate https certificates for each domain, and redirect traffic to the smallweb evaluation server (caddy)
1717-- a service to map each domain to the corresponding folder in ~/smallweb, and spawn a deno subprocess for each request (smallweb)
1818-1919-## MacOS setup
2020-2121-In the future, we might provide a script to automate this process, but for now, it's a manual process.
2222-2323-### Install Brew
2424-2525-```sh
2626-# install homebrew (if not already installed)
2727-/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
2828-```
2929-3030-### Install Deno {#install-deno-macos}
3131-3232-```sh
3333-brew install deno
3434-```
3535-3636-### Setup Smallweb {#setup-smallweb-macos}
3737-3838-```sh
3939-brew install pomdtr/tap/smallweb
4040-smallweb service install
4141-```
4242-4343-### Setup Caddy {#setup-caddy-macos}
4444-4545-Caddy’s configuration path depends on whether you're using an Intel-based Mac or an Apple Silicon (M1/M2) Mac.
4646-4747-- **For Apple Silicon (M1/M2) Macs**:
4848- The default installation path is `/opt/homebrew/etc/Caddyfile`.
4949-- **For Intel-based Macs**:
5050- The default installation path is `/usr/local/etc/Caddyfile`.
5151-5252-#### Apple Silicon (M1/M2):
5353-5454-```sh
5555-brew install caddy
5656-5757-# Write caddy configuration
5858-cat <<EOF > /opt/homebrew/etc/Caddyfile
5959-localhost, *.localhost, *.*.localhost {
6060- tls internal {
6161- on_demand
6262- }
6363-6464- reverse_proxy localhost:7777
6565-}
6666-EOF
6767-```
6868-6969-#### Intel-based:
7070-7171-```sh
7272-brew install caddy
7373-7474-# Write caddy configuration
7575-cat <<EOF > /usr/local/etc/Caddyfile
7676-localhost, *.localhost, *.*.localhost {
7777- tls internal {
7878- on_demand
7979- }
8080-8181- reverse_proxy localhost:7777
8282-}
8383-EOF
8484-```
8585-8686-#### Run Caddy:
8787-8888-```sh
8989-# Run caddy in the background
9090-brew services start caddy
9191-9292-# Add caddy https certificates to your keychain
9393-caddy trust
9494-```
9595-9696-### Setup dnsmasq {#setup-dnsmasq-macos}
9797-9898-The configuration path for dnsmasq also depends on your Mac's architecture.
9999-100100-#### Apple Silicon (M1/M2):
101101-102102-```sh
103103-brew install dnsmasq
104104-105105-# Write dnsmasq configuration
106106-echo "address=/.localhost/127.0.0.1" >> /opt/homebrew/etc/dnsmasq.conf
107107-```
108108-109109-#### Intel-based:
110110-111111-```sh
112112-brew install dnsmasq
113113-114114-# Write dnsmasq configuration
115115-echo "address=/.localhost/127.0.0.1" >> /usr/local/etc/dnsmasq.conf
116116-```
117117-118118-#### Run dnsmasq:
119119-120120-```sh
121121-# Run dnsmasq in the background
122122-sudo brew services start dnsmasq
123123-124124-# Indicates to the system to use dnsmasq for .localhost domains
125125-sudo mkdir -p /etc/resolver
126126-cat <<EOF | sudo tee -a /etc/resolver/localhost
127127-nameserver 127.0.0.1
128128-EOF
129129-```
130130-131131-## Testing the setup {#testing-the-setup-macos}
132132-133133-First, let's create a dummy smallweb website:
134134-135135-```sh
136136-mkdir -p ~/smallweb/example
137137-cat <<EOF > ~/smallweb/example/main.ts
138138-export default {
139139- fetch() {
140140- return new Response("Smallweb is running", {
141141- headers: {
142142- "Content-Type": "text/plain",
143143- },
144144- });
145145- }
146146-}
147147-EOF
148148-```
149149-150150-If everything went well, you should be able to access `https://example.localhost` in your browser, and see the message `Smallweb is running`.
151151-152152-## Ubuntu / Debian setup
153153-154154-### Install Deno {#install-deno-ubuntu}
155155-156156-```sh
157157-curl -fsSL https://deno.land/install.sh | sh
158158-# add ~/.deno/bin to PATH
159159-echo "export PATH=\$PATH:\$HOME/.deno/bin" >> ~/.bashrc
160160-```
161161-162162-### Setup Smallweb {#setup-smallweb-ubuntu}
163163-164164-```sh
165165-curl -fsSL https://install.smallweb.run | sh
166166-# add ~/.local/bin to PATH
167167-echo "export PATH=\$PATH:\$HOME/.local/bin" >> ~/.bashrc
168168-smallweb service install
169169-```
170170-171171-### Setup Caddy {#setup-caddy-ubuntu}
172172-173173-```sh
174174-sudo apt install -y caddy
175175-176176-# Write caddy configuration
177177-cat <<EOF > /etc/caddy/Caddyfile
178178-*.localhost {
179179- tls internal {
180180- on_demand
181181- }
182182-183183- reverse_proxy localhost:7777
184184-}
185185-EOF
186186-187187-sudo systemctl restart caddy
188188-189189-caddy trust
190190-```
191191-192192-There is no need to setup dnsmasq on Ubuntu, as it seems to be already configured to resolve `.localhost` domains to `127.0.0.1`.
193193-194194-### Testing the setup {#testing-setup-ubuntu}
195195-196196-First, let's create a dummy smallweb website:
197197-198198-```sh
199199-mkdir -p ~/smallweb/example
200200-CAT <<EOF > ~/smallweb/example/main.ts
201201-export default {
202202- fetch() {
203203- return new Response("Smallweb is running", {
204204- headers: {
205205- "Content-Type": "text/plain",
206206- },
207207- });
208208- }
209209-}
210210-EOF
211211-```
212212-213213-If everything went well, you should be able to access `https://example.localhost` in your browser, and see the message `Smallweb is running`.
-60
docs/src/hosting/vps.md
···11-# VPS / Home Server
22-33-If you're using a Debian-based Server, you can follow these steps to setup smallweb, assuming you're logged in as root.
44-55-These steps will also work on other distributions, but you may need to adjust the package manager commands.
66-77-```bash
88-# create user with homedir and default shell
99-useradd --system --user-group --create-home --shell $(which bash) smallweb
1010-1111-# set a password for the smallweb user
1212-passwd smallweb
1313-1414-# give the user sudo access (optional)
1515-usermod -aG sudo smallweb
1616-1717-# allow the user to use systemd
1818-usermod -aG systemd-journal smallweb
1919-2020-# run user services on login
2121-loginctl enable-linger smallweb
2222-```
2323-2424-At this point, you can switch to the `smallweb` user (ex: using `ssh smallweb@<ip>`) and install smallweb:
2525-2626-```bash
2727-# install unzip (required for deno)
2828-sudo apt update && sudo apt install unzip
2929-3030-# install deno
3131-curl -fsSL https://deno.land/install.sh | sh # install deno
3232-3333-# install smallweb
3434-curl -sSfL https://install.smallweb.run | sh # install smallweb
3535-3636-# start the smallweb service
3737-smallweb service install
3838-```
3939-4040-To make your service accessible from the internet, you have multiple options:
4141-4242-- setup a reverse proxy on port 443 (I use caddy)
4343-- using cloudflare tunnel (see [cloudflare setup](./cloudflare/cloudflare.md))
4444-4545-## Syncing files using mutagen
4646-4747-I recommend using [mutagen](https://mutagen.io) to sync your files between your development machine and the server.
4848-4949-First, install mutagen on your development machine, then enable the daemon using `mutagen daemon register`, and finally, run the following command to sync your files:
5050-5151-```bash
5252-mutagen sync create --name=smallweb --ignore-vcs --ignore=node_modules \
5353- ~/smallweb smallweb@<server-ip>:/home/smallweb/smallweb
5454-```
5555-5656-From now on, each time you make a change to your files, they will be automatically synced to the server, and vice versa.
5757-5858-Your git repository will only be present on one machine, you can choose if you want to keep it on your development machine or on the server. Syncing git repositories [is not recommended](https://mutagen.io/documentation/synchronization/version-control-systems).
5959-6060-I also prefer to skip syncing the `node_modules` folder, as deno automatically fetches them when needed.
-60
docs/src/reference/app_config.md
···11-# App Configuration Reference
22-33-The smallweb configuration can be defined in a `smallweb.json[c]` file at the root of the project. This config file is optional, and sensible defaults are used when it is not present.
44-55-## Available Fields
66-77-### `entrypoint`
88-99-The `entrypoint` field defines the file to serve. If this field is not provided, the app will look for a `main.[js,ts,jsx,tsx]` file in the root directory.
1010-1111-### `root`
1212-1313-The `root` field defines the root directory of the app. If this field is not provided, the app will use the app directory as the root directory.
1414-1515-### `private`
1616-1717-If the `private` field is set to `true`, the app will ask for your admin username and password before serving the app using basic auth.
1818-1919-### `privateRoutes`
2020-2121-If you only want to protect a subset of routes, you can use the `privateRoutes` field. This field is an array of routes that require authentication.
2222-2323-```json
2424-{
2525- "privateRoutes": [
2626- "/private",
2727- "/admin/*"
2828- ]
2929-}
3030-```
3131-3232-### `publicRoutes`
3333-3434-If you want to make a subset of routes public, you can use the `publicRoutes` field. This field is an array of routes that do not require authentication.
3535-3636-```json
3737-{
3838- "private": true,
3939- "publicRoutes": [
4040- "/public/*",
4141- ]
4242-}
4343-```
4444-4545-### `crons`
4646-4747-The `crons` field defines a list of cron jobs to run. See the [Cron Jobs](../guides/cron.md) guide for more information.
4848-4949-```json
5050-{
5151- "crons": [
5252- {
5353- "name": "daily-task", // The name of the cron task (required)
5454- "description": "A daily task", // A description for the task (optional)
5555- "schedule": "0 0 * * *", // a cron expression (required)
5656- "args": [] // arguments to pass to the task (required)
5757- }
5858- ]
5959-}
6060-```
-701
docs/src/reference/cli.md
···11-# CLI Reference
22-33-## smallweb
44-55-Host websites from your internet folder
66-77-### Options
88-99-```
1010- -h, --help help for smallweb
1111-```
1212-1313-## smallweb api
1414-1515-Interact with the smallweb API
1616-1717-```
1818-smallweb api [flags]
1919-```
2020-2121-### Options
2222-2323-```
2424- -d, --data string Data to send in the request body
2525- -H, --header stringArray HTTP headers to use
2626- -h, --help help for api
2727- -X, --method string HTTP method to use (default "GET")
2828-```
2929-3030-## smallweb capture
3131-3232-Extension capture
3333-3434-```
3535-smallweb capture [flags]
3636-```
3737-3838-### Options
3939-4040-```
4141- -h, --help help for capture
4242-```
4343-4444-## smallweb changelog
4545-4646-Show the changelog
4747-4848-```
4949-smallweb changelog [flags]
5050-```
5151-5252-### Options
5353-5454-```
5555- -h, --help help for changelog
5656-```
5757-5858-## smallweb clone
5959-6060-Clone an app
6161-6262-```
6363-smallweb clone [app] [new-name] [flags]
6464-```
6565-6666-### Options
6767-6868-```
6969- -h, --help help for clone
7070-```
7171-7272-## smallweb completion
7373-7474-Generate the autocompletion script for the specified shell
7575-7676-### Synopsis
7777-7878-Generate the autocompletion script for smallweb for the specified shell.
7979-See each sub-command's help for details on how to use the generated script.
8080-8181-8282-### Options
8383-8484-```
8585- -h, --help help for completion
8686-```
8787-8888-## smallweb completion bash
8989-9090-Generate the autocompletion script for bash
9191-9292-### Synopsis
9393-9494-Generate the autocompletion script for the bash shell.
9595-9696-This script depends on the 'bash-completion' package.
9797-If it is not installed already, you can install it via your OS's package manager.
9898-9999-To load completions in your current shell session:
100100-101101- source <(smallweb completion bash)
102102-103103-To load completions for every new session, execute once:
104104-105105-#### Linux:
106106-107107- smallweb completion bash > /etc/bash_completion.d/smallweb
108108-109109-#### macOS:
110110-111111- smallweb completion bash > $(brew --prefix)/etc/bash_completion.d/smallweb
112112-113113-You will need to start a new shell for this setup to take effect.
114114-115115-116116-```
117117-smallweb completion bash
118118-```
119119-120120-### Options
121121-122122-```
123123- -h, --help help for bash
124124- --no-descriptions disable completion descriptions
125125-```
126126-127127-## smallweb completion fish
128128-129129-Generate the autocompletion script for fish
130130-131131-### Synopsis
132132-133133-Generate the autocompletion script for the fish shell.
134134-135135-To load completions in your current shell session:
136136-137137- smallweb completion fish | source
138138-139139-To load completions for every new session, execute once:
140140-141141- smallweb completion fish > ~/.config/fish/completions/smallweb.fish
142142-143143-You will need to start a new shell for this setup to take effect.
144144-145145-146146-```
147147-smallweb completion fish [flags]
148148-```
149149-150150-### Options
151151-152152-```
153153- -h, --help help for fish
154154- --no-descriptions disable completion descriptions
155155-```
156156-157157-## smallweb completion powershell
158158-159159-Generate the autocompletion script for powershell
160160-161161-### Synopsis
162162-163163-Generate the autocompletion script for powershell.
164164-165165-To load completions in your current shell session:
166166-167167- smallweb completion powershell | Out-String | Invoke-Expression
168168-169169-To load completions for every new session, add the output of the above command
170170-to your powershell profile.
171171-172172-173173-```
174174-smallweb completion powershell [flags]
175175-```
176176-177177-### Options
178178-179179-```
180180- -h, --help help for powershell
181181- --no-descriptions disable completion descriptions
182182-```
183183-184184-## smallweb completion zsh
185185-186186-Generate the autocompletion script for zsh
187187-188188-### Synopsis
189189-190190-Generate the autocompletion script for the zsh shell.
191191-192192-If shell completion is not already enabled in your environment you will need
193193-to enable it. You can execute the following once:
194194-195195- echo "autoload -U compinit; compinit" >> ~/.zshrc
196196-197197-To load completions in your current shell session:
198198-199199- source <(smallweb completion zsh)
200200-201201-To load completions for every new session, execute once:
202202-203203-#### Linux:
204204-205205- smallweb completion zsh > "${fpath[1]}/_smallweb"
206206-207207-#### macOS:
208208-209209- smallweb completion zsh > $(brew --prefix)/share/zsh/site-functions/_smallweb
210210-211211-You will need to start a new shell for this setup to take effect.
212212-213213-214214-```
215215-smallweb completion zsh [flags]
216216-```
217217-218218-### Options
219219-220220-```
221221- -h, --help help for zsh
222222- --no-descriptions disable completion descriptions
223223-```
224224-225225-## smallweb config
226226-227227-Open the smallweb config in your editor
228228-229229-```
230230-smallweb config [key] [flags]
231231-```
232232-233233-### Options
234234-235235-```
236236- -h, --help help for config
237237-```
238238-239239-## smallweb create
240240-241241-Create a new smallweb app
242242-243243-```
244244-smallweb create <app> [flags]
245245-```
246246-247247-### Options
248248-249249-```
250250- -h, --help help for create
251251-```
252252-253253-## smallweb cron
254254-255255-Manage cron jobs
256256-257257-### Options
258258-259259-```
260260- -h, --help help for cron
261261-```
262262-263263-## smallweb cron list
264264-265265-List cron jobs
266266-267267-```
268268-smallweb cron list [flags]
269269-```
270270-271271-### Options
272272-273273-```
274274- --app string filter by app
275275- -h, --help help for list
276276- --json output as json
277277-```
278278-279279-## smallweb cron trigger
280280-281281-Trigger a cron job
282282-283283-```
284284-smallweb cron trigger <id> [flags]
285285-```
286286-287287-### Options
288288-289289-```
290290- -h, --help help for trigger
291291-```
292292-293293-## smallweb delete
294294-295295-Delete an app
296296-297297-```
298298-smallweb delete [flags]
299299-```
300300-301301-### Options
302302-303303-```
304304- -h, --help help for delete
305305-```
306306-307307-## smallweb docs
308308-309309-Generate smallweb cli documentation
310310-311311-```
312312-smallweb docs [flags]
313313-```
314314-315315-### Options
316316-317317-```
318318- -h, --help help for docs
319319-```
320320-321321-## smallweb edit
322322-323323-Extension edit
324324-325325-```
326326-smallweb edit [flags]
327327-```
328328-329329-### Options
330330-331331-```
332332- -h, --help help for edit
333333-```
334334-335335-## smallweb gallery
336336-337337-Extension gallery
338338-339339-```
340340-smallweb gallery [flags]
341341-```
342342-343343-### Options
344344-345345-```
346346- -h, --help help for gallery
347347-```
348348-349349-## smallweb hello
350350-351351-Extension hello
352352-353353-```
354354-smallweb hello [flags]
355355-```
356356-357357-### Options
358358-359359-```
360360- -h, --help help for hello
361361-```
362362-363363-## smallweb list
364364-365365-List all smallweb apps
366366-367367-```
368368-smallweb list [flags]
369369-```
370370-371371-### Options
372372-373373-```
374374- -h, --help help for list
375375- --json output as json
376376-```
377377-378378-## smallweb log
379379-380380-Show logs
381381-382382-### Options
383383-384384-```
385385- -h, --help help for log
386386-```
387387-388388-## smallweb log console
389389-390390-Show console logs
391391-392392-```
393393-smallweb log console [flags]
394394-```
395395-396396-### Options
397397-398398-```
399399- --app string filter logs by app
400400- -h, --help help for console
401401- --json output logs in JSON format
402402-```
403403-404404-## smallweb log cron
405405-406406-Show cron logs
407407-408408-```
409409-smallweb log cron [flags]
410410-```
411411-412412-### Options
413413-414414-```
415415- -h, --help help for cron
416416- --host string filter logs by host
417417- --json output logs in JSON format
418418-```
419419-420420-## smallweb log http
421421-422422-Show HTTP logs
423423-424424-```
425425-smallweb log http [flags]
426426-```
427427-428428-### Options
429429-430430-```
431431- -h, --help help for http
432432- --host string filter logs by host
433433- --json output logs in JSON format
434434-```
435435-436436-## smallweb open
437437-438438-Open an app in the browser
439439-440440-```
441441-smallweb open [app] [flags]
442442-```
443443-444444-### Options
445445-446446-```
447447- -h, --help help for open
448448-```
449449-450450-## smallweb rename
451451-452452-Rename an app
453453-454454-```
455455-smallweb rename [app] [new-name] [flags]
456456-```
457457-458458-### Options
459459-460460-```
461461- -h, --help help for rename
462462-```
463463-464464-## smallweb run
465465-466466-Run an app cli
467467-468468-```
469469-smallweb run <app> [args...] [flags]
470470-```
471471-472472-### Options
473473-474474-```
475475- -h, --help help for run
476476-```
477477-478478-## smallweb service
479479-480480-Manage smallweb service
481481-482482-### Options
483483-484484-```
485485- -h, --help help for service
486486-```
487487-488488-## smallweb service install
489489-490490-Install smallweb as a service
491491-492492-```
493493-smallweb service install [flags]
494494-```
495495-496496-### Options
497497-498498-```
499499- -h, --help help for install
500500-```
501501-502502-## smallweb service logs
503503-504504-Print service logs
505505-506506-```
507507-smallweb service logs [flags]
508508-```
509509-510510-### Options
511511-512512-```
513513- -f, --follow Follow log output
514514- -h, --help help for logs
515515-```
516516-517517-## smallweb service restart
518518-519519-Restart smallweb service
520520-521521-```
522522-smallweb service restart [flags]
523523-```
524524-525525-### Options
526526-527527-```
528528- -h, --help help for restart
529529-```
530530-531531-## smallweb service start
532532-533533-Start smallweb service
534534-535535-```
536536-smallweb service start [flags]
537537-```
538538-539539-### Options
540540-541541-```
542542- -h, --help help for start
543543-```
544544-545545-## smallweb service status
546546-547547-View service status
548548-549549-```
550550-smallweb service status [flags]
551551-```
552552-553553-### Options
554554-555555-```
556556- -h, --help help for status
557557-```
558558-559559-## smallweb service stop
560560-561561-Stop smallweb service
562562-563563-```
564564-smallweb service stop [flags]
565565-```
566566-567567-### Options
568568-569569-```
570570- -h, --help help for stop
571571-```
572572-573573-## smallweb service uninstall
574574-575575-Uninstall smallweb service
576576-577577-```
578578-smallweb service uninstall [flags]
579579-```
580580-581581-### Options
582582-583583-```
584584- -h, --help help for uninstall
585585-```
586586-587587-## smallweb token
588588-589589-Manage api tokens
590590-591591-### Options
592592-593593-```
594594- -h, --help help for token
595595-```
596596-597597-## smallweb token create
598598-599599-Create a new token
600600-601601-```
602602-smallweb token create [flags]
603603-```
604604-605605-### Options
606606-607607-```
608608- --admin admin token
609609- -a, --app strings app token
610610- -d, --description string description of the token
611611- -h, --help help for create
612612-```
613613-614614-## smallweb token delete
615615-616616-Remove a token
617617-618618-```
619619-smallweb token delete <id> [flags]
620620-```
621621-622622-### Options
623623-624624-```
625625- -h, --help help for delete
626626-```
627627-628628-## smallweb token list
629629-630630-List all tokens
631631-632632-```
633633-smallweb token list [flags]
634634-```
635635-636636-### Options
637637-638638-```
639639- -h, --help help for list
640640- -j, --json output as JSON
641641-```
642642-643643-## smallweb tunnel
644644-645645-Start a tunnel to a remote server (powered by localhost.run)
646646-647647-```
648648-smallweb tunnel [flags]
649649-```
650650-651651-### Options
652652-653653-```
654654- -h, --help help for tunnel
655655-```
656656-657657-## smallweb up
658658-659659-Start the smallweb evaluation server
660660-661661-```
662662-smallweb up [flags]
663663-```
664664-665665-### Options
666666-667667-```
668668- -h, --help help for up
669669-```
670670-671671-## smallweb upgrade
672672-673673-Upgrade to the latest version
674674-675675-```
676676-smallweb upgrade [version] [flags]
677677-```
678678-679679-### Options
680680-681681-```
682682- -h, --help help for upgrade
683683-```
684684-685685-## smallweb view
686686-687687-Extension view
688688-689689-```
690690-smallweb view [flags]
691691-```
692692-693693-### Options
694694-695695-```
696696- -h, --help help for view
697697-```
698698-699699-700700-701701-<!-- markdownlint-disable-file -->
-113
docs/src/reference/global_config.md
···11-# Global Config
22-33-The smallweb config is located at `~/.config/smallweb/config.json[c]`. It is a json file that defines global settings for smallweb.
44-55-You can also specify a custom config file by setting the `SMALLWEB_CONFIG` environment variable.
66-77-Smallweb also respects the `XDG_CONFIG_HOME` environment variable.
88-99-## Available Fields
1010-1111-### `addr`
1212-1313-The `addr` field defines the addr to bind to. By default, it is `:7777`.
1414-1515-```json
1616-{
1717- "addr": "127.0.0.1:8000"
1818-}
1919-```
2020-2121-If you want to use an unix socket, you can use the `unix/` prefix.
2222-2323-```json
2424-{
2525- "addr": "unix/~/smallweb.sock"
2626-}
2727-```
2828-2929-### `cert` and `key`
3030-3131-The `cert` and `key` fields define the path to the SSL certificate and key.
3232-3333-```json
3434-{
3535- "cert": "~/cert.pem",
3636- "key": "~/key.pem"
3737-}
3838-```
3939-4040-### `domain`
4141-4242-The `domain` field defines the apex domain used for routing.
4343-4444-```json
4545-{
4646- "domain": "example.com"
4747-}
4848-```
4949-5050-See the [Routing](../guides/routing.md) guide for more information.
5151-5252-### `dir`
5353-5454-The `dir` field defines the root directory for all apps.
5555-5656-```json
5757-{
5858- "dir": "~/smallweb"
5959-}
6060-```
6161-6262-### `email`
6363-6464-The `email` field is required to enable lastlogin authentication for private apps.
6565-6666-If it is not set, private will show a basic auth prompt instead.
6767-6868-```json
6969-{
7070- "email": "pomdtr@example.com"
7171-}
7272-```
7373-7474-### `customDomains`
7575-7676-The `customDomains` field is an object that maps custom domains to apps.
7777-7878-```json
7979-{
8080- "customDomains": {
8181- "example.com": "example",
8282- }
8383-}
8484-```
8585-8686-## Default Config
8787-8888-By default the config file looks like this:
8989-9090-```json
9191-{
9292- "addr": ":7777",
9393- "dir": "~/smallweb",
9494-}
9595-```
9696-9797-Since smallweb requires a domain to be set, the minimal config is:
9898-9999-```json
100100-{
101101- "domain": "example.com"
102102-}
103103-```
104104-105105-which is equivalent to:
106106-107107-```json
108108-{
109109- "domain": "example.com",
110110- "addr": ":7777",
111111- "dir": "~/smallweb",
112112-}
113113-```