Skip to content

Commit

Permalink
add example: redirect (#694)
Browse files Browse the repository at this point in the history
  • Loading branch information
hubertshelley authored Feb 26, 2024
1 parent 5dff369 commit 685ad76
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
11 changes: 11 additions & 0 deletions examples/redirect/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[package]
name = "example-redirect"
version.workspace = true
edition.workspace = true
publish.workspace = true

[dependencies]
salvo = { workspace = true }
tokio = { workspace = true, features = ["macros"] }
tracing.workspace = true
tracing-subscriber.workspace = true
15 changes: 15 additions & 0 deletions examples/redirect/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use salvo::prelude::*;

#[handler]
async fn hello(res: &mut Response) {
res.render(Redirect::found("https://www.rust-lang.org/"))
}

#[tokio::main]
async fn main() {
tracing_subscriber::fmt().init();

let acceptor = TcpListener::new("0.0.0.0:5800").bind().await;
let router = Router::new().get(hello);
Server::new(acceptor).serve(router).await;
}

0 comments on commit 685ad76

Please sign in to comment.