> This article is also available in HTML at: http://www.vincentbruijn.nl/articles/msaada/
> For a full index of articles, see: http://www.vincentbruijn.nl/llms.txt

# Serve any directory locally on any port

- **Date**: 2023-09-19
- **Author**: Vincent Bruijn
- **Description**: Introducing msaada, a simple static file web server for development
- **Keywords**: rust, webserver

---

For fast prototyping I create tiny projects consiting of some HTML files with JavaScript and CSS assets. Instead of opening them with the file protocol in the browser, I like them served over HTTP. I used to use `php -S` for this, but I do not want PHP on my machine, so I had to find an alternative. I wrote the alternative in [Rust](https://www.rust-lang.org/).


My first Rust project this is, and I named it msaada, Swahili for servant. And that is what it is: a small static file server written in Rust, based on `actix-web` and using `clap`.

```sh
$ msaada -p 3001 -d .
```

Imagine you're prototyping a small webapp, usually I find myself creating an `index.html` and some `.js` and `.css` files: let's get going with this `canvas` based idea! Or whatever – I mean, I like to have those served over HTTP instead of `file://`.

I remember PHP has `php -S localhost:8000` for rapid development. And lately I used python's `python3 -m http.server 8000` which basically do the same. But I find the Python approach hard to remember, and I could write a shell script around that of course, but I saw it as a challange to write something myself.

Since I am lately playing around with Rust a little, I decided to write the server in Rust, based on `actix-web`. I wanted to create a command line application with some options so I imported `clap` also. With some support of AI code helpers I was able to write a simple web server. It will only serve static files and will initially look for an `index.html` when it receives a `GET` request.

This thing is of course a development tool, not meant for production. Usually I'd go with something like:

```sh
$ cd Projects
$ mkdir my-prototype
$ cd my-prototype
$ touch index.html
$ code .
$ msaada -p 3001 -d .
[2023-09-18T14:17:16Z INFO  msaada] starting HTTP server at http://localhost:3004
```

You can find the [repo on Github](https://github.com/y-a-v-a/msaada). If you are interested in how to release Rust based artifacts to the `Releases` page, check out the workflows [file](https://github.com/y-a-v-a/msaada/blob/main/.github/workflows/release.yaml) in `.github/workflows/release.yaml`

The nice thing about [clap](https://crates.io/crates/clap) is that it automatically creates help output, based on your configured command line arguments. A next step could be to add some attribution of myself, but I haven't actually yet considered doing so.

```sh
$ msaada --help
Usage: msaada --port <port> --dir <directory>

Options:
  -p, --port <port>      The port number to use
  -d, --dir <directory>  The directory to serve from
  -h, --help             Print help
```
