-
Notifications
You must be signed in to change notification settings - Fork 86
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 #616 from hermit-os/axum
feat: add axum example
- Loading branch information
Showing
3 changed files
with
30 additions
and
0 deletions.
There are no files selected for viewing
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,10 @@ | ||
[package] | ||
name = "axum-example" | ||
edition = "2021" | ||
|
||
[dependencies] | ||
axum = "0.7" | ||
tokio = "1" | ||
|
||
[target.'cfg(target_os = "hermit")'.dependencies] | ||
hermit = { path = "../../hermit" } |
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,19 @@ | ||
use axum::routing::get; | ||
use axum::Router; | ||
#[cfg(target_os = "hermit")] | ||
use hermit as _; | ||
use tokio::{io, net}; | ||
|
||
#[tokio::main(flavor = "current_thread")] | ||
async fn main() -> io::Result<()> { | ||
let app = Router::new().route("/", get(root)); | ||
|
||
let listener = net::TcpListener::bind("0.0.0.0:9975").await?; | ||
axum::serve(listener, app).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn root() -> &'static str { | ||
"Hello, World!" | ||
} |