Giter VIP home page Giter VIP logo

binserve's Introduction

binserve โšก๐Ÿฆ€

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! ๐ŸŽ‰

version GitHub license Twitter

Table of Contents


Features

  • 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 and port in the binserve.json.
  • Easiest Routing - you just have to enter the route and the static file to respond in the binserve.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! And images, css, and js falls under the assets 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.

Hello World!

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

โš™๏ธ Configuration File:

๐Ÿ“„ 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!

๐ŸŽจ Templates:

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.

Build From Source

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

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.

Contribution

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!

License

Licensed under the MIT License, see LICENSE for more information.

Liked the project?

Support the author by buying him a coffee!

Buy Me A Coffee


Support this project by starring โญ, sharing ๐Ÿ“ฒ, and contributing ๐Ÿ‘ฉโ€๐Ÿ’ป! โค๏ธ


binserve's People

Contributors

amythicdev avatar mufeedvh avatar nicolaiunrein avatar rivy avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.