Skip to content

Commit

Permalink
created axum boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
TheButlah committed Aug 3, 2024
1 parent 79d54b0 commit ed47264
Show file tree
Hide file tree
Showing 6 changed files with 102 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[workspace]
resolver = "2"
members = [
"apps/identity_server",
"apps/legacy_web/backend",
"apps/legacy_web/frontend",
"apps/networked_physics_demo/client",
Expand Down Expand Up @@ -29,6 +30,7 @@ rust-version = "1.78.0"

[workspace.dependencies]
async-compat = "0.2.4"
axum = "0.7.5"
base64 = "0.21.7"
bevy = { version = "0.13", features = ["serialize"] }
bevy-inspector-egui = "0.23.4"
Expand Down Expand Up @@ -69,6 +71,7 @@ thiserror = "1.0.56"
tokio = { version = "1.35.1", default-features = false }
tokio-serde = "0.9"
tokio-util = { version = "0.7.10", default-features = true }
tower-http = "0.5.2"
tracing = "0.1.40"
tracing-subscriber = "0.3.18"
url = "2.5.0"
Expand Down
19 changes: 19 additions & 0 deletions apps/identity_server/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
[package]
name = "identity_server"
version.workspace = true
license.workspace = true
repository.workspace = true
edition.workspace = true
rust-version.workspace = true
description = "Self-custodial identity using did:web"
publish = false

[dependencies]
axum.workspace = true
clap.workspace = true
color-eyre.workspace = true
tokio = { workspace = true, features = ["full"] }
tower-http = { workspace = true, features = ["trace"] }
tracing-subscriber = { workspace = true, features = ["env-filter"] }
tracing.workspace = true
serde.workspace = true
16 changes: 16 additions & 0 deletions apps/identity_server/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
pub mod v1;

use axum::routing::get;
use tower_http::trace::TraceLayer;

/// Main router of API
pub fn router() -> axum::Router<()> {
axum::Router::new()
.route("/", get(root))
.nest("/api/v1", crate::v1::router())
.layer(TraceLayer::new_for_http())
}

async fn root() -> &'static str {
"uwu hewwo this api is under constwuction"
}
33 changes: 33 additions & 0 deletions apps/identity_server/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
use std::net::{Ipv6Addr, SocketAddr};

use clap::Parser as _;
use tracing::info;
use tracing_subscriber::{layer::SubscriberExt, util::SubscriberInitExt, EnvFilter};

#[derive(clap::Parser, Debug)]
struct Cli {
#[clap(default_value = "0")]
port: u16,
}

#[tokio::main]
async fn main() -> color_eyre::Result<()> {
color_eyre::install()?;
tracing_subscriber::registry()
.with(EnvFilter::try_from_default_env().unwrap_or("info".into()))
.with(tracing_subscriber::fmt::layer())
.init();

let cli = Cli::parse();

let listener = tokio::net::TcpListener::bind(SocketAddr::new(
Ipv6Addr::UNSPECIFIED.into(),
cli.port,
))
.await
.unwrap();
info!("listening on {}", listener.local_addr().unwrap());
axum::serve(listener, identity_server::router())
.await
.map_err(|e| e.into())
}
17 changes: 17 additions & 0 deletions apps/identity_server/src/v1/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
//! V1 of the API. This is subject to change until we commit to stability, after
//! which point any breaking changes will go in a V2 api.

use axum::{routing::post, Json, Router};
use serde::{Deserialize, Serialize};

/// Router of API V1
pub fn router() -> Router {
Router::new().route("/create", post(create))
}

async fn create(_pubkey: Json<JWK>) -> String {
String::from("did:web:todo")
}

#[derive(Debug, Serialize, Deserialize)]
struct JWK;

0 comments on commit ed47264

Please sign in to comment.