-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from salvo-rs/db
add some middleware
- Loading branch information
Showing
10 changed files
with
143 additions
and
9 deletions.
There are no files selected for viewing
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use rust_embed::RustEmbed; | ||
use salvo::{Router, serve_static::static_embed, endpoint, Response, http::ResBody, hyper::body::Bytes}; | ||
|
||
#[derive(RustEmbed)] | ||
#[folder = "assets"] | ||
struct Assets; | ||
|
||
pub fn create_static_routers() -> Vec<Router> { | ||
{{#if need_db_conn}} | ||
let static_router = Router::with_path("assets/<**path>").get(static_embed::<Assets>()); | ||
let icon_router = Router::with_path("favicon.ico").get(get_icon); | ||
vec![static_router,icon_router] | ||
{{else}} | ||
let icon_router = Router::with_path("favicon.ico").get(get_icon); | ||
vec![icon_router] | ||
{{/if}} | ||
} | ||
|
||
#[endpoint(tags("comm"))] | ||
pub async fn get_icon(res: &mut Response) { | ||
let icon = Assets::get("favicon.ico").unwrap(); | ||
res.body(ResBody::Once(Bytes::from(icon.data.to_vec()))); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters