Giter Club home page Giter Club logo

static-server's Introduction

static-server

simple static file server written in Rust based on axum framework

screenshot

I'm learning Rust and axum.

My thought is simple.

axum has a static-file-server example, which only serve static files under a directory and does not list the directory index.

it also has a templates example which uses askama as template engine to parse a Jinja2 like template.

I thought I could simply combine the code of the two and my job is done -_-

But things didn't go in the way I thought

why created this ?

long time ago, I used to start a static http server like this (using the python3 built-in http server) :

python3 -m http.server -d .

since I'm learning Rust, and I found an interesting web framework that is Axum, I want to use Axum to implement a simple static server mainly for studying purposes.

the python one support some command line flags:

❯ python3 -m http.server -h
usage: server.py [-h] [--cgi] [--bind ADDRESS] [--directory DIRECTORY] [port]

positional arguments:
  port                  Specify alternate port [default: 8000]

optional arguments:
  -h, --help            show this help message and exit
  --cgi                 Run as CGI Server
  --bind ADDRESS, -b ADDRESS
                        Specify alternate bind address [default: all interfaces]
  --directory DIRECTORY, -d DIRECTORY
                        Specify alternative directory [default:current directory]

so does this one:

❯ static-server -h
static-server 0.4.2
A simple static file server written in Rust based on axum framework.

USAGE:
    static-server [OPTIONS]

FLAGS:
    -h, --help       Prints help information
    -V, --version    Prints version information

OPTIONS:
    -a, --addr <addr>        set the listen addr [default: 127.0.0.1]
    -l, --log <log-level>    set the log level [default: debug]
    -p, --port <port>        set the listen port [default: 3000]
    -r, --root <root-dir>    set the root directory [default: .]

TODO

use https://github.com/sampotts/plyr for audio,video

https://github.com/tokio-rs/axum/blob/main/axum/CHANGELOG.md

Related Projects

https://github.com/eliben/static-server

static-server's People

Contributors

copie avatar dependabot[bot] avatar ttys3 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

static-server's Issues

use of `oneshot` on `ServeDir` prevents compilation

Thank you for sharing this codebase. It is helping me get up to speed on how to use Axum.

The following line is preventing my compiling the code. The underlying libraries are changing really fast... (the Cargo.caml files seem to match...)

return match ServeDir::new(&cfg.root_dir).oneshot(req).await { .. }

I'm working out the fix as I work through the types. If I find a solution, I'll be sure to post accordingly.

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.