A blazingly fast static web server with routing, templating, and security in a single binary you can set up with zero code. 🔥
UPDATE: Next version will be releasing soon with Automatic TLS (HTTPS), More speed, SEO features, and much more! 🎉
- Features
- Quick Start
- Configuration
- Templates
- Build From Source
- Security
- Contribution
- License
- Support The Author
- Single binary with no dependencies and everything built-in.
- Blazingly fast! ⚡ - it's built on top of Actix, one of the fastest web frameworks in the world and of course, written in Rust.
- Everything in a single config file - everything you need to setup is in the
binserve.json
, just change it, run it! - Epic Portability - just carry the binary around and all you have to change is the
host
andport
in thebinserve.json
. - Easiest Routing - you just have to enter the
route
and thestatic file
to respond in thebinserve.json
to add a route entry! - Handlebars template engine - renders every static file with
Handlebars
on the first run improving performance! - Template Variables in one place - that too in the one and only config file!
- Secure by design - runs security validation checks on the first run and will only run the server once configuration is confirmed secure! (See Security)
- Config & Static File Assistance - just running it will create the configuration file and the static directory boilerplate for you!
- Supports Any Static Files - just give any static file of your choice to routes and response will match it's
Content-Type
. - Straightforward Directory Structure - static files falls under the
static
directory, you can even change that! Andimages
,css
, andjs
falls under theassets
directory which should all be created for you in the first run itself! - Custom Error Page Support - you can design your own fancy error pages!
- Actix Logging Middleware - Logging is powered directly from Actix.
Download the binary for your OS from Releases, then just run it:
$ binserve
That's it. Done! You should see the following output:
_ _
| |_|_|___ ___ ___ ___ _ _ ___
| . | | |_ -| -_| _| | | -_|
|___|_|_|_|___|___|_| \_/|___| v0.1.0
Your server is up and running at http://example.com:80/
Here is how the directory structure will look like:
├── binserve
├── binserve.json
├── rendered_templates
│ ├── 404.html
│ └── index.html
└── static
├── 404.html
├── assets
│ ├── css
│ ├── images
│ └── js
└── index.html
📄 File: binserve.json
{
"directory_listing": false,
"enable_logging": true,
"error_pages": {
"404": "404.html"
},
"follow_symlinks": false,
"routes": {
"/": "index.html",
"/example": "example.html"
},
"server": {
"host": "127.0.0.1",
"port": 1337
},
"static_directory": "static",
"template_variables": {
"load_static": "/static/",
"name": "Binserve"
}
}
The whole thing revolves around this configuration file, whatever changes you want to make, just edit the config and run it!
binserve
uses Handlebars as the template engine as it perfectly fits our use case.
Here is an example:
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>My name is {{name}}</h1>
</body>
</html>
Now add your name in the config file (binserve.json
) as a template variable
:
"template_variables": {
"load_static": "/static/",
"name": "Keanu Reeves"
}
Now run the server!
$ binserve
This would render down to:
<html>
<head>
<title>Example</title>
</head>
<body>
<h1>My name is Keanu Reeves</h1>
</body>
</html>
To load static files such as images
, css
, and javascript
, just use {{load_static}}
:
load_static
is specified in the binserve.json
itself.
<img src="{{load_static}}images/rick_roll.gif">
<link rel="stylesheet" href="{{load_static}}css/main.css">
<script src="{{load_static}}js/script.js">
binserve
renders all your template at once on the first run itself to improve performance as it wouldn't have to render the template on each request.
For building binserve from source, you need to have these tools installed
- Git
- Rust
- Cargo (Automatically installed when installing Rust)
- A C linker (Only for Linux, generally comes pre-installed)
$ git clone https://github.com/mufeedvh/binserve.git
$ cd binserve/
$ cargo build --release
The first command clones the binserve repository in your local machine. The next two commands changes into the binserve directory and builds it in release mode
Security is one of the most crucial elements in a web server, binserve
is secure by design. Here is how it's secure:
- Routes are specified in the configuration file not directly accepted from the user.
- Runs a check for Path Traversal attempts in routes in the configuration file on each run.
- Runs a check for Symlink Files which might point to sensitive files on each run.
- Only Follows Symlinks when explicitly allowed in the configuration file which is disabled by default.
- Only enables Directory Listing when explicitly allowed in the configuration file which is disabled by default.
Ways to contribute
- Suggest a feature
- Report a bug
- Fix something and open a pull request
- Help me document the code
- Spread the word
- Create an example with binserve and you will be featured here!
Licensed under the MIT License, see LICENSE for more information.
Support the author by buying him a coffee!
Support this project by starring ⭐, sharing 📲, and contributing 👩💻! ❤️