this repo has no description
1pub mod api; 2pub mod appview; 3pub mod auth; 4pub mod cache; 5pub mod circuit_breaker; 6pub mod comms; 7pub mod config; 8pub mod crawlers; 9pub mod delegation; 10pub mod handle; 11pub mod image; 12pub mod metrics; 13pub mod oauth; 14pub mod plc; 15pub mod rate_limit; 16pub mod repo; 17pub mod state; 18pub mod storage; 19pub mod sync; 20pub mod util; 21pub mod validation; 22 23use axum::{ 24 Router, 25 http::Method, 26 middleware, 27 routing::{any, get, post}, 28}; 29use state::AppState; 30use tower_http::cors::{Any, CorsLayer}; 31use tower_http::services::{ServeDir, ServeFile}; 32 33pub fn app(state: AppState) -> Router { 34 let router = Router::new() 35 .route("/metrics", get(metrics::metrics_handler)) 36 .route("/health", get(api::server::health)) 37 .route("/xrpc/_health", get(api::server::health)) 38 .route("/robots.txt", get(api::server::robots_txt)) 39 .route("/logo", get(api::server::get_logo)) 40 .route( 41 "/xrpc/com.atproto.server.describeServer", 42 get(api::server::describe_server), 43 ) 44 .route( 45 "/xrpc/com.atproto.server.createAccount", 46 post(api::identity::create_account), 47 ) 48 .route( 49 "/xrpc/com.atproto.server.createSession", 50 post(api::server::create_session), 51 ) 52 .route( 53 "/xrpc/com.atproto.server.getSession", 54 get(api::server::get_session), 55 ) 56 .route( 57 "/xrpc/com.tranquil.account.listSessions", 58 get(api::server::list_sessions), 59 ) 60 .route( 61 "/xrpc/com.tranquil.account.revokeSession", 62 post(api::server::revoke_session), 63 ) 64 .route( 65 "/xrpc/com.tranquil.account.revokeAllSessions", 66 post(api::server::revoke_all_sessions), 67 ) 68 .route( 69 "/xrpc/com.atproto.server.deleteSession", 70 post(api::server::delete_session), 71 ) 72 .route( 73 "/xrpc/com.atproto.server.refreshSession", 74 post(api::server::refresh_session), 75 ) 76 .route( 77 "/xrpc/com.atproto.server.confirmSignup", 78 post(api::server::confirm_signup), 79 ) 80 .route( 81 "/xrpc/com.atproto.server.resendVerification", 82 post(api::server::resend_verification), 83 ) 84 .route( 85 "/xrpc/com.atproto.server.getServiceAuth", 86 get(api::server::get_service_auth), 87 ) 88 .route( 89 "/xrpc/com.atproto.identity.resolveHandle", 90 get(api::identity::resolve_handle), 91 ) 92 .route( 93 "/xrpc/com.atproto.repo.createRecord", 94 post(api::repo::create_record), 95 ) 96 .route( 97 "/xrpc/com.atproto.repo.putRecord", 98 post(api::repo::put_record), 99 ) 100 .route( 101 "/xrpc/com.atproto.repo.getRecord", 102 get(api::repo::get_record), 103 ) 104 .route( 105 "/xrpc/com.atproto.repo.deleteRecord", 106 post(api::repo::delete_record), 107 ) 108 .route( 109 "/xrpc/com.atproto.repo.listRecords", 110 get(api::repo::list_records), 111 ) 112 .route( 113 "/xrpc/com.atproto.repo.describeRepo", 114 get(api::repo::describe_repo), 115 ) 116 .route( 117 "/xrpc/com.atproto.repo.uploadBlob", 118 post(api::repo::upload_blob), 119 ) 120 .route( 121 "/xrpc/com.atproto.repo.applyWrites", 122 post(api::repo::apply_writes), 123 ) 124 .route( 125 "/xrpc/com.atproto.sync.getLatestCommit", 126 get(sync::get_latest_commit), 127 ) 128 .route("/xrpc/com.atproto.sync.listRepos", get(sync::list_repos)) 129 .route("/xrpc/com.atproto.sync.getBlob", get(sync::get_blob)) 130 .route("/xrpc/com.atproto.sync.listBlobs", get(sync::list_blobs)) 131 .route( 132 "/xrpc/com.atproto.sync.getRepoStatus", 133 get(sync::get_repo_status), 134 ) 135 .route( 136 "/xrpc/com.atproto.server.checkAccountStatus", 137 get(api::server::check_account_status), 138 ) 139 .route( 140 "/xrpc/com.atproto.identity.getRecommendedDidCredentials", 141 get(api::identity::get_recommended_did_credentials), 142 ) 143 .route( 144 "/xrpc/com.atproto.repo.listMissingBlobs", 145 get(api::repo::list_missing_blobs), 146 ) 147 .route( 148 "/xrpc/com.atproto.sync.notifyOfUpdate", 149 post(sync::notify_of_update), 150 ) 151 .route( 152 "/xrpc/com.atproto.sync.requestCrawl", 153 post(sync::request_crawl), 154 ) 155 .route("/xrpc/com.atproto.sync.getBlocks", get(sync::get_blocks)) 156 .route("/xrpc/com.atproto.sync.getRepo", get(sync::get_repo)) 157 .route("/xrpc/com.atproto.sync.getRecord", get(sync::get_record)) 158 .route( 159 "/xrpc/com.atproto.sync.subscribeRepos", 160 get(sync::subscribe_repos), 161 ) 162 .route("/xrpc/com.atproto.sync.getHead", get(sync::get_head)) 163 .route( 164 "/xrpc/com.atproto.sync.getCheckout", 165 get(sync::get_checkout), 166 ) 167 .route( 168 "/xrpc/com.atproto.moderation.createReport", 169 post(api::moderation::create_report), 170 ) 171 .route( 172 "/xrpc/com.atproto.admin.getAccountInfo", 173 get(api::admin::get_account_info), 174 ) 175 .route( 176 "/xrpc/com.atproto.admin.getAccountInfos", 177 get(api::admin::get_account_infos), 178 ) 179 .route( 180 "/xrpc/com.atproto.admin.searchAccounts", 181 get(api::admin::search_accounts), 182 ) 183 .route( 184 "/xrpc/com.atproto.server.activateAccount", 185 post(api::server::activate_account), 186 ) 187 .route( 188 "/xrpc/com.atproto.server.deactivateAccount", 189 post(api::server::deactivate_account), 190 ) 191 .route( 192 "/xrpc/com.atproto.server.requestAccountDelete", 193 post(api::server::request_account_delete), 194 ) 195 .route( 196 "/xrpc/com.atproto.server.deleteAccount", 197 post(api::server::delete_account), 198 ) 199 .route( 200 "/xrpc/com.atproto.server.requestPasswordReset", 201 post(api::server::request_password_reset), 202 ) 203 .route( 204 "/xrpc/com.atproto.server.resetPassword", 205 post(api::server::reset_password), 206 ) 207 .route( 208 "/xrpc/com.tranquil.account.changePassword", 209 post(api::server::change_password), 210 ) 211 .route( 212 "/xrpc/com.tranquil.account.removePassword", 213 post(api::server::remove_password), 214 ) 215 .route( 216 "/xrpc/com.tranquil.account.getPasswordStatus", 217 get(api::server::get_password_status), 218 ) 219 .route( 220 "/xrpc/com.tranquil.account.getReauthStatus", 221 get(api::server::get_reauth_status), 222 ) 223 .route( 224 "/xrpc/com.tranquil.account.reauthPassword", 225 post(api::server::reauth_password), 226 ) 227 .route( 228 "/xrpc/com.tranquil.account.reauthTotp", 229 post(api::server::reauth_totp), 230 ) 231 .route( 232 "/xrpc/com.tranquil.account.reauthPasskeyStart", 233 post(api::server::reauth_passkey_start), 234 ) 235 .route( 236 "/xrpc/com.tranquil.account.reauthPasskeyFinish", 237 post(api::server::reauth_passkey_finish), 238 ) 239 .route( 240 "/xrpc/com.tranquil.account.getLegacyLoginPreference", 241 get(api::server::get_legacy_login_preference), 242 ) 243 .route( 244 "/xrpc/com.tranquil.account.updateLegacyLoginPreference", 245 post(api::server::update_legacy_login_preference), 246 ) 247 .route( 248 "/xrpc/com.tranquil.account.updateLocale", 249 post(api::server::update_locale), 250 ) 251 .route( 252 "/xrpc/com.tranquil.account.listTrustedDevices", 253 get(api::server::list_trusted_devices), 254 ) 255 .route( 256 "/xrpc/com.tranquil.account.revokeTrustedDevice", 257 post(api::server::revoke_trusted_device), 258 ) 259 .route( 260 "/xrpc/com.tranquil.account.updateTrustedDevice", 261 post(api::server::update_trusted_device), 262 ) 263 .route( 264 "/xrpc/com.tranquil.account.createPasskeyAccount", 265 post(api::server::create_passkey_account), 266 ) 267 .route( 268 "/xrpc/com.tranquil.account.startPasskeyRegistrationForSetup", 269 post(api::server::start_passkey_registration_for_setup), 270 ) 271 .route( 272 "/xrpc/com.tranquil.account.completePasskeySetup", 273 post(api::server::complete_passkey_setup), 274 ) 275 .route( 276 "/xrpc/com.tranquil.account.requestPasskeyRecovery", 277 post(api::server::request_passkey_recovery), 278 ) 279 .route( 280 "/xrpc/com.tranquil.account.recoverPasskeyAccount", 281 post(api::server::recover_passkey_account), 282 ) 283 .route( 284 "/xrpc/com.atproto.server.requestEmailUpdate", 285 post(api::server::request_email_update), 286 ) 287 .route( 288 "/xrpc/com.atproto.server.confirmEmail", 289 post(api::server::confirm_email), 290 ) 291 .route( 292 "/xrpc/com.atproto.server.updateEmail", 293 post(api::server::update_email), 294 ) 295 .route( 296 "/xrpc/com.atproto.server.reserveSigningKey", 297 post(api::server::reserve_signing_key), 298 ) 299 .route( 300 "/xrpc/com.atproto.server.verifyMigrationEmail", 301 post(api::server::verify_migration_email), 302 ) 303 .route( 304 "/xrpc/com.atproto.server.resendMigrationVerification", 305 post(api::server::resend_migration_verification), 306 ) 307 .route( 308 "/xrpc/com.atproto.identity.updateHandle", 309 post(api::identity::update_handle), 310 ) 311 .route( 312 "/xrpc/com.atproto.identity.requestPlcOperationSignature", 313 post(api::identity::request_plc_operation_signature), 314 ) 315 .route( 316 "/xrpc/com.atproto.identity.signPlcOperation", 317 post(api::identity::sign_plc_operation), 318 ) 319 .route( 320 "/xrpc/com.atproto.identity.submitPlcOperation", 321 post(api::identity::submit_plc_operation), 322 ) 323 .route( 324 "/xrpc/com.atproto.repo.importRepo", 325 post(api::repo::import_repo), 326 ) 327 .route( 328 "/xrpc/com.atproto.admin.deleteAccount", 329 post(api::admin::delete_account), 330 ) 331 .route( 332 "/xrpc/com.atproto.admin.updateAccountEmail", 333 post(api::admin::update_account_email), 334 ) 335 .route( 336 "/xrpc/com.atproto.admin.updateAccountHandle", 337 post(api::admin::update_account_handle), 338 ) 339 .route( 340 "/xrpc/com.atproto.admin.updateAccountPassword", 341 post(api::admin::update_account_password), 342 ) 343 .route( 344 "/xrpc/com.atproto.server.listAppPasswords", 345 get(api::server::list_app_passwords), 346 ) 347 .route( 348 "/xrpc/com.atproto.server.createAppPassword", 349 post(api::server::create_app_password), 350 ) 351 .route( 352 "/xrpc/com.atproto.server.revokeAppPassword", 353 post(api::server::revoke_app_password), 354 ) 355 .route( 356 "/xrpc/com.atproto.server.createInviteCode", 357 post(api::server::create_invite_code), 358 ) 359 .route( 360 "/xrpc/com.atproto.server.createInviteCodes", 361 post(api::server::create_invite_codes), 362 ) 363 .route( 364 "/xrpc/com.atproto.server.getAccountInviteCodes", 365 get(api::server::get_account_invite_codes), 366 ) 367 .route( 368 "/xrpc/com.atproto.server.createTotpSecret", 369 post(api::server::create_totp_secret), 370 ) 371 .route( 372 "/xrpc/com.atproto.server.enableTotp", 373 post(api::server::enable_totp), 374 ) 375 .route( 376 "/xrpc/com.atproto.server.disableTotp", 377 post(api::server::disable_totp), 378 ) 379 .route( 380 "/xrpc/com.atproto.server.getTotpStatus", 381 get(api::server::get_totp_status), 382 ) 383 .route( 384 "/xrpc/com.atproto.server.regenerateBackupCodes", 385 post(api::server::regenerate_backup_codes), 386 ) 387 .route( 388 "/xrpc/com.atproto.server.startPasskeyRegistration", 389 post(api::server::start_passkey_registration), 390 ) 391 .route( 392 "/xrpc/com.atproto.server.finishPasskeyRegistration", 393 post(api::server::finish_passkey_registration), 394 ) 395 .route( 396 "/xrpc/com.atproto.server.listPasskeys", 397 get(api::server::list_passkeys), 398 ) 399 .route( 400 "/xrpc/com.atproto.server.deletePasskey", 401 post(api::server::delete_passkey), 402 ) 403 .route( 404 "/xrpc/com.atproto.server.updatePasskey", 405 post(api::server::update_passkey), 406 ) 407 .route( 408 "/xrpc/com.atproto.admin.getInviteCodes", 409 get(api::admin::get_invite_codes), 410 ) 411 .route( 412 "/xrpc/com.tranquil.admin.getServerStats", 413 get(api::admin::get_server_stats), 414 ) 415 .route( 416 "/xrpc/com.tranquil.server.getConfig", 417 get(api::admin::get_server_config), 418 ) 419 .route( 420 "/xrpc/com.tranquil.admin.updateServerConfig", 421 post(api::admin::update_server_config), 422 ) 423 .route( 424 "/xrpc/com.atproto.admin.disableAccountInvites", 425 post(api::admin::disable_account_invites), 426 ) 427 .route( 428 "/xrpc/com.atproto.admin.enableAccountInvites", 429 post(api::admin::enable_account_invites), 430 ) 431 .route( 432 "/xrpc/com.atproto.admin.disableInviteCodes", 433 post(api::admin::disable_invite_codes), 434 ) 435 .route( 436 "/xrpc/com.atproto.admin.getSubjectStatus", 437 get(api::admin::get_subject_status), 438 ) 439 .route( 440 "/xrpc/com.atproto.admin.updateSubjectStatus", 441 post(api::admin::update_subject_status), 442 ) 443 .route( 444 "/xrpc/com.atproto.admin.sendEmail", 445 post(api::admin::send_email), 446 ) 447 .route( 448 "/xrpc/app.bsky.actor.getPreferences", 449 get(api::actor::get_preferences), 450 ) 451 .route( 452 "/xrpc/app.bsky.actor.putPreferences", 453 post(api::actor::put_preferences), 454 ) 455 .route("/.well-known/did.json", get(api::identity::well_known_did)) 456 .route( 457 "/.well-known/atproto-did", 458 get(api::identity::well_known_atproto_did), 459 ) 460 .route("/u/{handle}/did.json", get(api::identity::user_did_doc)) 461 .route( 462 "/.well-known/oauth-protected-resource", 463 get(oauth::endpoints::oauth_protected_resource), 464 ) 465 .route( 466 "/.well-known/oauth-authorization-server", 467 get(oauth::endpoints::oauth_authorization_server), 468 ) 469 .route("/oauth/jwks", get(oauth::endpoints::oauth_jwks)) 470 .route( 471 "/oauth/client-metadata.json", 472 get(oauth::endpoints::frontend_client_metadata), 473 ) 474 .route( 475 "/oauth/par", 476 post(oauth::endpoints::pushed_authorization_request), 477 ) 478 .route("/oauth/authorize", get(oauth::endpoints::authorize_get)) 479 .route("/oauth/authorize", post(oauth::endpoints::authorize_post)) 480 .route( 481 "/oauth/authorize/accounts", 482 get(oauth::endpoints::authorize_accounts), 483 ) 484 .route( 485 "/oauth/authorize/select", 486 post(oauth::endpoints::authorize_select), 487 ) 488 .route( 489 "/oauth/authorize/2fa", 490 get(oauth::endpoints::authorize_2fa_get), 491 ) 492 .route( 493 "/oauth/authorize/2fa", 494 post(oauth::endpoints::authorize_2fa_post), 495 ) 496 .route( 497 "/oauth/authorize/passkey", 498 get(oauth::endpoints::authorize_passkey_start), 499 ) 500 .route( 501 "/oauth/authorize/passkey", 502 post(oauth::endpoints::authorize_passkey_finish), 503 ) 504 .route( 505 "/oauth/passkey/check", 506 get(oauth::endpoints::check_user_has_passkeys), 507 ) 508 .route( 509 "/oauth/security-status", 510 get(oauth::endpoints::check_user_security_status), 511 ) 512 .route( 513 "/oauth/passkey/start", 514 post(oauth::endpoints::passkey_start), 515 ) 516 .route( 517 "/oauth/passkey/finish", 518 post(oauth::endpoints::passkey_finish), 519 ) 520 .route( 521 "/oauth/authorize/deny", 522 post(oauth::endpoints::authorize_deny), 523 ) 524 .route( 525 "/oauth/authorize/consent", 526 get(oauth::endpoints::consent_get), 527 ) 528 .route( 529 "/oauth/authorize/consent", 530 post(oauth::endpoints::consent_post), 531 ) 532 .route( 533 "/oauth/delegation/auth", 534 post(oauth::endpoints::delegation_auth), 535 ) 536 .route( 537 "/oauth/delegation/totp", 538 post(oauth::endpoints::delegation_totp_verify), 539 ) 540 .route("/oauth/token", post(oauth::endpoints::token_endpoint)) 541 .route("/oauth/revoke", post(oauth::endpoints::revoke_token)) 542 .route( 543 "/oauth/introspect", 544 post(oauth::endpoints::introspect_token), 545 ) 546 .route( 547 "/xrpc/com.atproto.temp.checkSignupQueue", 548 get(api::temp::check_signup_queue), 549 ) 550 .route( 551 "/xrpc/com.atproto.temp.dereferenceScope", 552 post(api::temp::dereference_scope), 553 ) 554 .route( 555 "/xrpc/com.tranquil.account.getNotificationPrefs", 556 get(api::notification_prefs::get_notification_prefs), 557 ) 558 .route( 559 "/xrpc/com.tranquil.account.updateNotificationPrefs", 560 post(api::notification_prefs::update_notification_prefs), 561 ) 562 .route( 563 "/xrpc/com.tranquil.account.getNotificationHistory", 564 get(api::notification_prefs::get_notification_history), 565 ) 566 .route( 567 "/xrpc/com.tranquil.account.confirmChannelVerification", 568 post(api::verification::confirm_channel_verification), 569 ) 570 .route( 571 "/xrpc/com.tranquil.account.verifyToken", 572 post(api::server::verify_token), 573 ) 574 .route( 575 "/xrpc/com.tranquil.delegation.listControllers", 576 get(api::delegation::list_controllers), 577 ) 578 .route( 579 "/xrpc/com.tranquil.delegation.addController", 580 post(api::delegation::add_controller), 581 ) 582 .route( 583 "/xrpc/com.tranquil.delegation.removeController", 584 post(api::delegation::remove_controller), 585 ) 586 .route( 587 "/xrpc/com.tranquil.delegation.updateControllerScopes", 588 post(api::delegation::update_controller_scopes), 589 ) 590 .route( 591 "/xrpc/com.tranquil.delegation.listControlledAccounts", 592 get(api::delegation::list_controlled_accounts), 593 ) 594 .route( 595 "/xrpc/com.tranquil.delegation.getAuditLog", 596 get(api::delegation::get_audit_log), 597 ) 598 .route( 599 "/xrpc/com.tranquil.delegation.getScopePresets", 600 get(api::delegation::get_scope_presets), 601 ) 602 .route( 603 "/xrpc/com.tranquil.delegation.createDelegatedAccount", 604 post(api::delegation::create_delegated_account), 605 ) 606 .route("/xrpc/{*method}", any(api::proxy::proxy_handler)) 607 .layer(middleware::from_fn(metrics::metrics_middleware)) 608 .layer( 609 CorsLayer::new() 610 .allow_origin(Any) 611 .allow_methods([Method::GET, Method::POST, Method::OPTIONS]) 612 .allow_headers(Any), 613 ) 614 .with_state(state); 615 616 let frontend_dir = 617 std::env::var("FRONTEND_DIR").unwrap_or_else(|_| "./frontend/dist".to_string()); 618 619 if std::path::Path::new(&frontend_dir) 620 .join("index.html") 621 .exists() 622 { 623 let index_path = format!("{}/index.html", frontend_dir); 624 let serve_dir = ServeDir::new(&frontend_dir).not_found_service(ServeFile::new(index_path)); 625 router.fallback_service(serve_dir) 626 } else { 627 router 628 } 629}