- 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
}
ServeDirandServeFilestruct:new(path) -> Selfmethod and builder-style options methods.Into<Ohkami>that convert it into anOhkamiinstance that serves a directory or a file.Route::Byto takeimpl Into<Ohkami>, instead ofOhkami.Route::Mountspecial method is not needed at all. Remove it to simplifyRouteinterface.before:
after: