···
use crate::{CachedRecord, Repo, error::ServerError};
use tokio_util::sync::CancellationToken;
-
use poem::{Route, Server, listener::TcpListener};
ApiResponse, Object, OpenApi, OpenApiService, param::Query, payload::Json, types::Example,
···
// those are a little bit important
cache: HybridCache<String, CachedRecord>,
_shutdown: CancellationToken,
) -> Result<(), ServerError> {
let repo = Arc::new(repo);
···
.server("http://localhost:3000")
.nest("/", api_service.scalar())
.nest("/openapi.json", api_service.spec_endpoint())
.nest("/xrpc/", api_service);
Server::new(TcpListener::bind("127.0.0.1:3000"))
···
use crate::{CachedRecord, Repo, error::ServerError};
use tokio_util::sync::CancellationToken;
+
use poem::{Endpoint, Route, Server, endpoint::make_sync, listener::TcpListener};
ApiResponse, Object, OpenApi, OpenApiService, param::Query, payload::Json, types::Example,
···
// those are a little bit important
+
#[derive(Debug, Clone, Serialize)]
+
#[serde(rename_all = "camelCase")]
+
struct AppViewService {
+
service_endpoint: String,
+
#[derive(Debug, Clone, Serialize)]
+
service: [AppViewService; 1],
+
/// Serve a did document for did:web for this to be an xrpc appview
+
/// No slingshot endpoints currently require auth, so it's not necessary to do
+
/// service proxying, however clients may wish to:
+
/// - PDS proxying offers a level of client IP anonymity from slingshot
+
/// - slingshot *may* implement more generous per-user rate-limits for proxied requests in the future
+
fn get_did_doc(host: String) -> impl Endpoint {
+
let doc = poem::web::Json(AppViewDoc {
+
id: format!("did:web:{host}"),
+
service: [AppViewService {
+
id: "#slingshot".to_string(),
+
r#type: "SlingshotRecordProxy".to_string(),
+
service_endpoint: format!("https://{host}"),
+
make_sync(move |_| doc.clone())
cache: HybridCache<String, CachedRecord>,
_shutdown: CancellationToken,
) -> Result<(), ServerError> {
let repo = Arc::new(repo);
···
.server("http://localhost:3000")
+
let mut app = Route::new()
.nest("/", api_service.scalar())
.nest("/openapi.json", api_service.spec_endpoint())
.nest("/xrpc/", api_service);
+
if let Some(host) = host {
+
app = app.at("/.well-known/did.json", get_did_doc(host));
Server::new(TcpListener::bind("127.0.0.1:3000"))