mirror of
https://github.com/aljazceru/pubky-core.git
synced 2026-01-14 11:44:32 +01:00
feat(homeserver): add Server header with version number
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
//! The controller part of the [crate::HomeserverCore]
|
||||
|
||||
use axum::{
|
||||
body::Body,
|
||||
extract::Request,
|
||||
http::{header, HeaderValue},
|
||||
middleware::{self, Next},
|
||||
response::Response,
|
||||
routing::{get, post},
|
||||
Router,
|
||||
};
|
||||
use tower::ServiceBuilder;
|
||||
use tower_cookies::CookieManagerLayer;
|
||||
use tower_http::cors::CorsLayer;
|
||||
|
||||
@@ -16,6 +22,7 @@ mod feed;
|
||||
mod root;
|
||||
mod tenants;
|
||||
|
||||
static HOMESERVER_VERSION: &str = concat!("pubky.org", "@", env!("CARGO_PKG_VERSION"),);
|
||||
const TRACING_EXCLUDED_PATHS: [&str; 1] = ["/events/"];
|
||||
|
||||
fn base() -> Router<AppState> {
|
||||
@@ -35,7 +42,20 @@ pub fn create_app(state: AppState) -> Router {
|
||||
.merge(tenants::router(state.clone()))
|
||||
.layer(CookieManagerLayer::new())
|
||||
.layer(CorsLayer::very_permissive())
|
||||
.layer(ServiceBuilder::new().layer(middleware::from_fn(add_server_header)))
|
||||
.with_state(state);
|
||||
|
||||
with_trace_layer(app, &TRACING_EXCLUDED_PATHS).layer(PubkyHostLayer)
|
||||
}
|
||||
|
||||
// Middleware to add a `Server` header to all responses
|
||||
async fn add_server_header(request: Request<Body>, next: Next) -> Response {
|
||||
let mut response = next.run(request).await;
|
||||
|
||||
// Add a custom header to the response
|
||||
response
|
||||
.headers_mut()
|
||||
.insert(header::SERVER, HeaderValue::from_static(HOMESERVER_VERSION));
|
||||
|
||||
response
|
||||
}
|
||||
|
||||
@@ -45,9 +45,7 @@ impl ClientBuilder {
|
||||
self.pkarr
|
||||
.bootstrap(&[format!(
|
||||
"localhost:{}",
|
||||
// TODO: update constants
|
||||
// pubky_common::constants::testnet_ports::BOOTSTRAP
|
||||
6881
|
||||
pubky_common::constants::testnet_ports::BOOTSTRAP
|
||||
)])
|
||||
.relays(&[format!(
|
||||
"http://localhost:{}",
|
||||
|
||||
Reference in New Issue
Block a user