#web-server #kvarn #server-framework #config-format #extension #website #reference

bin+lib moella

An implementation of the Kvarn web server framework with a convenient config format

2 releases

0.1.1 Feb 11, 2024
0.1.0 Feb 4, 2024

#348 in HTTP server

30 downloads per month

Apache-2.0 and GPL-2.0-or-later

88KB
2K SLoC

Mölla

This is the reference implementation of the Kvarn server library, offering a simple config to get you started using Kvarn.

See moella --help for config options

It's e.g. currently used by my domains icelk.dev and kvarn.org.

See kvarn.org for an example config and the schema of the config. You can also take a look at the icelk.dev config for a production example.

Usage

First install moella.

Next, create a config file, let's say host.ron:

(
    hosts: [
        Plain (
            name: "my-website.com",
            pk: "pk.pem",
            cert: "cert.pem",
            auto_cert: true,
            path: "./",
            extensions: ["arbetrary-name"],
            options: (
                public_data_directory: "build",
                disable_server_cache: true,
                disable_client_cache: false,
            )
        ),
    ],
    extensions: {
        "arbetrary-name": [
            // most of this can be removed; it's just an example
            Csp ({
                "/*": FromDefault ({
                    script_src: [UnsafeInline, WasmUnsafeEval],
                    style_src: [
                        Uri("https://fonts.googleapis.com"),
                        Uri("https://fonts.googleapis.com"),
                        UnsafeInline,
                    ],
                    default_src: [ Uri("https://fonts.gstatic.com") ],
                    img_src: [Uri("*"), Scheme("data:")]
                }),
                // SVG XSS attacks if viewing file
                "/groups/logo-images/*": FromDefault ({}),

            }),
            ClientCache ({
                "/": MaxAge(3600),
                "/_app/immutable/": Full,
                "/groups/logo-images/": Changing,
                "/groups/data": Changing,
                "/groups/locations": Changing,
            }),
        ]
    },
    import: [/* some other config file */],
    ports: Standard(All),
)

Now, run moella -c host.ron --dev. Your website should be working. Remove the --dev flag when deploying.

See kvarn.org for more details.

Installation

If you have cargo installed, simply run cargo install moella.

There are builds available for Linux in Github Actions, and for other platforms under Releases.

To run it, download the binary appropriate for your platform.

  • Platform specifics:
    • If you run Linux: run chmod +x <downloaded binary> to make it executable.
    • If you run macOS: run chmod +x <downloaded binary>, then open Finder and find the binary. Right click and click Open. Accept the warning.
    • On Windows, it should just run
  • Lastly, run the command ./<downloaded binary> --help in your shell to get usage information.

Build from latest source

Install Rust and then run the following:

This doesn't currently work, as we haven't published to crates.io yet. You'll have to set up the development environment.

$ cargo install moella

Documentation

Development

During development, Mölla requires Kvarn to be cloned at ../kvarn, Kvarn Search at ../kvarn-search, and Kvarn Auth at ../kvarn-auth.

Dependencies

~26–38MB
~704K SLoC