-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
37cf9c9
commit 27e6357
Showing
2 changed files
with
27 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
use axum::{routing::get, Router}; | ||
use color_eyre::eyre::Result; | ||
use tracing::info; | ||
|
||
pub struct App; | ||
|
||
impl App { | ||
pub fn new() -> Self { Self } | ||
|
||
pub async fn serve(&self) -> Result<()> { | ||
let app = Router::new().route("/", get(|| async { "Hello, World!" })); | ||
|
||
let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_string()); | ||
let host = std::env::var("HOST").unwrap_or_else(|_| "0.0.0.0".to_string()); | ||
let address = format!("{}:{}", host, port); | ||
let listener = tokio::net::TcpListener::bind(&address).await?; | ||
|
||
info!("listening on {}", address); | ||
axum::serve(listener, app).await?; | ||
|
||
Ok(()) | ||
} | ||
} |
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 |
---|---|---|
@@ -1,23 +1,15 @@ | ||
use axum::{routing::get, Router}; | ||
pub mod app; | ||
|
||
use color_eyre::eyre::Result; | ||
use tracing::info; | ||
|
||
#[tokio::main] | ||
async fn main() -> Result<()> { | ||
color_eyre::install()?; | ||
let subscriber = tracing_subscriber::fmt().finish(); | ||
tracing::subscriber::set_global_default(subscriber)?; | ||
|
||
let app = Router::new().route("/", get(|| async { "Hello, World!" })); | ||
|
||
// run our app with hyper, listening globally on port 3000 | ||
let port = std::env::var("PORT").unwrap_or_else(|_| "3000".to_string()); | ||
let host = std::env::var("HOST").unwrap_or_else(|_| "0.0.0.0".to_string()); | ||
let address = format!("{}:{}", host, port); | ||
let listener = tokio::net::TcpListener::bind(&address).await?; | ||
|
||
info!("Listening on {}", address); | ||
axum::serve(listener, app).await?; | ||
let app = app::App::new(); | ||
app.serve().await?; | ||
|
||
Ok(()) | ||
} |