-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(homeserver): remove EntryPath extractor and add Authz and PubkyH…
…ost layers
- Loading branch information
Showing
8 changed files
with
86 additions
and
129 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
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 |
---|---|---|
@@ -1,46 +1,36 @@ | ||
//! The controller part of the [crate::HomeserverCore] | ||
use axum::{ | ||
routing::{delete, get, post}, | ||
routing::{get, post}, | ||
Router, | ||
}; | ||
use tower_cookies::CookieManagerLayer; | ||
use tower_http::{cors::CorsLayer, trace::TraceLayer}; | ||
|
||
use crate::core::AppState; | ||
|
||
use super::layers::pubky_host::PubkyHostLayer; | ||
|
||
mod auth; | ||
mod feed; | ||
mod public; | ||
mod root; | ||
mod tenants; | ||
|
||
fn base() -> Router<AppState> { | ||
Router::new() | ||
.route("/", get(root::handler)) | ||
.route("/signup", post(auth::signup)) | ||
.route("/session", post(auth::signin)) | ||
// Routes for Pubky in the Hostname. | ||
// | ||
// The default and wortks with native Pubky client. | ||
// - Session routes | ||
.route("/session", get(auth::session)) | ||
.route("/session", delete(auth::signout)) | ||
// - Data routes | ||
// Events | ||
.route("/events/", get(feed::feed)) | ||
.layer(CookieManagerLayer::new()) | ||
// TODO: add size limit | ||
// TODO: revisit if we enable streaming big payloads | ||
// TODO: maybe add to a separate router (drive router?). | ||
} | ||
|
||
pub fn create_app(state: AppState) -> Router { | ||
base() | ||
.merge(public::data_store_router(state.clone())) | ||
.merge(tenants::router(state.clone())) | ||
.layer(CookieManagerLayer::new()) | ||
.layer(CorsLayer::very_permissive()) | ||
.layer(TraceLayer::new_for_http()) | ||
.layer(PubkyHostLayer) | ||
.with_state(state) | ||
} |
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
//! Per Tenant (user / Pubky) routes. | ||
//! | ||
//! Every route here is relative to a tenant's Pubky host, | ||
//! as opposed to routes relative to the Homeserver's owner. | ||
use axum::{ | ||
extract::DefaultBodyLimit, | ||
routing::{delete, get, head, put}, | ||
Router, | ||
}; | ||
|
||
use crate::core::{ | ||
layers::{authz::AuthorizationLayer, pubky_host::PubkyHostLayer}, | ||
AppState, | ||
}; | ||
|
||
use super::auth; | ||
|
||
pub mod read; | ||
pub mod write; | ||
|
||
pub fn router(state: AppState) -> Router<AppState> { | ||
Router::new() | ||
// - Datastore routes | ||
.route("/pub/", get(read::get)) | ||
.route("/pub/*path", get(read::get)) | ||
.route("/pub/*path", head(read::head)) | ||
.route("/pub/*path", put(write::put)) | ||
.route("/pub/*path", delete(write::delete)) | ||
// - Session routes | ||
.route("/session", get(auth::session)) | ||
.route("/session", delete(auth::signout)) | ||
// Layers | ||
// TODO: different max size for sessions and other routes? | ||
.layer(DefaultBodyLimit::max(100 * 1024 * 1024)) | ||
.layer(AuthorizationLayer::new(state.clone())) | ||
.layer(PubkyHostLayer) | ||
} |
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
Oops, something went wrong.