Crates.io | simplestatic |
lib.rs | simplestatic |
version | 1.0.4 |
source | src |
created_at | 2021-04-08 23:05:43.767799 |
updated_at | 2021-04-09 11:42:22.93044 |
description | lightweight and minimalistic single-page webserver |
homepage | https://github.com/Transyhdistys/simplestatic |
repository | https://github.com/Transyhdistys/simplestatic |
max_upload_size | |
id | 381069 |
size | 104,834 |
Simple Static is a simple http web server that serves one simple http file and other possible resources. The reason for Simple Static's existance is to provide a back-end webserver for simple cases such as a maintenance page or a 404 page for cases where the proxy does not serve static sites itself.
Simple Static is able to embed javascript and css files from given paths to the html file and also handles Content-Security-Policy so that any inline styles or scripts are included in the CSP for maximum security.
Simple Static is also capable of serving other static content, but it's purpose is strictly to serve content like images for the main html file.
Run cargo install simplestatic
And then just run simplestatic
. Use --help
for help.
Simplestatic can be pulled from
ghcr.io/transyhdistys/simplestatic:latest
So running it can be simple as
docker run -dp 3333:3333 ghcr.io/transyhdistys/simplestatic:latest
Or for docker-compose
simplestatic:
image: ghcr.io/transyhdistys/simplestatic:latest
environment:
- SSTATIC_PORT: 3333 # See configuring for more
ports:
- 3333:3333
Simply install Rust and run cargo run
. It should not have other dependencies, and at least Rust 1.48 is new enough.
On my personal computer when testing with wrk, Simple Static is able to serve about 150,000 requests per second, which should be plenty for anything.
100 MB of RAM is probably plenty for all kinds of maintenance websites (unless if you're using big javascript libraries, in which case you may need more).
As for CPU I can't quite tell. A toaster should be able to run this, but with enough traffic it will probably eat all of the CPU you give it.
Configuration can be done in three different ways.
Environment Variables | Command-Line Arguments | config.toml | Description |
---|---|---|---|
SSTATIC_HTML_PATH |
--html |
html |
Path to the single html file. |
SSTATIC_JS_PATH |
--js |
js |
Path to the javascript file to embed, or folder containing the javascript files to embed. |
SSTATIC_CSS_PATH |
--css |
css |
Path to the css file to embed, or folder containing the css files to embed. |
SSTATIC_UNSAFE_INLINE |
--unsafe-inline |
unsafe_inline |
Allow usage of unsafe-inline CSP policy. |
SSTATIC_PORT |
--port |
port |
Port to bind to. |
SSTATIC_HOST |
--host |
host |
Host address to bind to. |
SSTATIC_STATIC_PATH |
--static-path |
static_path |
Path that will serve the static content |
SSTATIC_STATIC_CONTENT |
--static-content |
static_content |
Path of the content that will be served |
SSTATIC_MIME_TYPES |
--mime-types |
mime_types |
Path to file containing mime types. |
SSTATIC_CONFIG_PATH |
--config-path |
No option | Path to an optional config.toml file. |
The order in which these are prioritized from the first priority to last are
An example toml configuration can be found at config.sample.toml
. The default config file is config.toml
at working directory
and config.sample.toml
is configured to use the default configurations.
Simple Static supports a small bit of templating in order to customize the webpage for each request.
{{ js }}
and {{ css }}
in the html file. This is where it embeds any external
javascript and css files it finds respectively.What | Turns into |
---|---|
{{ Host }} |
Host -header |
{{ User-Agent }} |
User-Agent -header |
Simple Static is licensed under the AGPLv3 license.