Electric: Static Site hosting on Val Town

Electric is a lightweight static site hosting system built on Hono RPC and Val Town blob store, with a simple CLI. You can use Electric with your favorite static site generator, and add electric upload at the end of your build script.

Features

  • Simple File Management: Upload, download, list, and delete files through a RESTful API
  • Command Line Interface: Easy-to-use CLI for bulk operations with concurrent uploads
  • Authentication: Secure API access with bearer token authentication
  • Caching: Optimized content delivery with configurable cache settings
  • Val Town Integration: Leverages Val Town's blob storage for reliable file hosting

Host your own static site!

  1. Remix this Val by clicking the remix button
  2. Go to environmental variables, and set MASTER_BEARER to some secure code. You can use openssl rand -base64 32 to generate a cryptographically random one. Make sure to save it.
  3. [OPTIONAL] Set a vanity domain for the static site by going to backend/app.ts and choosing a new domain.
  4. Set the ROOT_URL environmental variable to that root url.
  5. Set the STORAGE_PREFIX to something that describes what the static website is. This is where the files will live.

Now, make sure you have Deno installed locally, and then

# Install the CLI tool deno install -grAf -n=electric https://esm.town/v/wolf/Electric/cli/mod.ts # Upload a directory of static files electric upload ./my-site # List your uploaded files electric list

For all CLI commands, run electric --help.

API Endpoints

The service exposes RESTful endpoints for programmatic access:

  • GET /api/index: List all files
  • POST /api/index: Upload a new file
  • GET /api/index/:path: Download a specific file
  • DELETE /api/index/:path: Delete a file