Skip to content

feat(Ohkami, Mount): add ServeDir, ServeFile struct & extend Route::By and remove Route::Mount #610

Description

@kanarus
  • Introduce explicit ServeDir and ServeFile struct:
    • each exposes new(path) -> Self method and builder-style options methods.
    • each implements Into<Ohkami> that convert it into an Ohkami instance that serves a directory or a file.
  • Extend Route::By to take impl Into<Ohkami>, instead of Ohkami.
  • Then Route::Mount special method is not needed at all. Remove it to simplify Route interface.

before:

use ohkami::{Ohkami, Route};

async fn main() {
    Ohkami::new((
        "/api".GET(async || "Hello, Ohkami!"),
        "/".Mount("./public")
            .serve_dotfiles(true)
            .omit_extensions(["html"])
    )).run("localhost:3000").await
}

after:

use ohkami::{Ohkami, Route};

async fn main() {
    Ohkami::new((
        "/api".GET(async || "Hello, Ohkami!"),
        "/".By(
            ohkami::ServeDir::new("./public")
            .serve_dotfiles(true)
            .omit_extensions(["html"])
        )
    )).run("localhost:3000").await
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    BREAKINGBreaking changeT-MountT-Ohkamirelated to `Ohkami` structfeatAdd a new feature

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions